Inconsistent Intersection.CurveLine behavior


I’m writing some code using RhinoCommon that relies upon finding the intersection of a curve and a line. The Intersection.CurveLine method is failing in certain situations. I’ve attached a command which demonstrates this. Please try the command with an input curve that is co-planar with the World XY plane and then try it with a curve which is not. It fails in the co-planar case. Thanks in advance.
ForTestingCommand.cs (2.1 KB)

Hi @jakemurphy0118,

See if this works any better:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  var rc = RhinoGet.GetOneObject("Select a curve", false, ObjectType.Curve, out var objRef);
  if (rc != Result.Success)
    return rc;

  var curve = objRef.Curve();
  if (null == curve)
    return Result.Failure;

  var plane = new Plane(Point3d.Origin, Vector3d.ZAxis);
  var planarCurve = Curve.ProjectToPlane(curve, plane);
  if (null == planarCurve)
    return Result.Failure;

  var tol = doc.ModelAbsoluteTolerance;
  var atol = doc.ModelAngleToleranceRadians;
  var pline = planarCurve.ToPolyline(tol, atol, 0, 0);

  for (var i = 0; i < pline.PointCount; i++)
    var point = pline.Point(i);
    if (planarCurve.ClosestPoint(point, out var t))
      point = planarCurve.PointAt(t);
      var line = new Line(point, point + Vector3d.ZAxis);
      var lineCurve = new LineCurve(line);
      var ccx = Intersection.CurveCurve(curve, lineCurve, tol, tol);
      if (!ccx.Any(x => x.IsPoint))


  return Result.Success;

1.) Intersection.CurveCurve just creates a LineCurve and then calls Intersection.CurveCurve. But before making the LineCurve, it does some monkey-business, assuming the user has an infinite line. I think this where the issue lies. So just make the (line) curve yourself.

2.) Doing this:

private static double Tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

is a bad idea, as the document tolerance changes every time you open a new file. But your variable is never updated. Best just to get it when you need it - it’s a quick call.

– Dale

Ah, okay that works. So if I use a LineCurve and Intersection.CurveCurve then I am in charge of making sure the line is long enough and I avoid the issue. Thanks for the help + advice.