Bug in Intersection.CurveLine

I am facing a bug in

 CurveIntersections CurveLine(
	Curve curve,
	Line line,
	double tolerance,
	double overlapTolerance()

If the line is short , then intersection is not found. after calling this method the line which I passed to the method becomes invalid (zero length). this is happening despite the fact that the Line is struct and it is passed by value not reference !

Hey @Ali5,

Is your line shorter than the tolerance you’re using when you call the method?

– cs

Nope. the line is 1 unit (mm) and the tolerance is 0.01.

Hi @Ali5,

Can you post a code sample and a file?

Thanks,

– Dale

Hi Dale,
try to see if you get an intersection by code, it works though when you bake the objects.

LineCurve lc = new LineCurve(
      new Point3d(-19.999999999999986, 140, -985),
      new Point3d(-19.999999999999986, 140, 335)
      );
    Line l = new Line(
      new Point3d(-19.999999999999986, 140, 5.0000000000000195),
      new Point3d(-19.999999999999986, 139, 5.0000000000000195)
      );
    l = new Line(l.From, l.Direction * 1000);

    CurveIntersections intersections = Intersection.CurveLine(
      lc,
      l,
      0.01,
      0.01);
    A = intersections.Count;
    B = lc;
    C = new LineCurve(l);

Hi @Ali5,

How about this?

  private void RunScript(ref object A, ref object B, ref object C)
  {
    var curve0 = new LineCurve(
      new Point3d(-19.999999999999986, 140, -985),
      new Point3d(-19.999999999999986, 140, 335)
      );

    var line0 = new Line(
      new Point3d(-19.999999999999986, 140, 5.0000000000000195),
      new Point3d(-19.999999999999986, 139, 5.0000000000000195)
      );

    var line1 = new Line(
      line0.From,
      line0.Direction * 1000
      );

    var curve1 = new LineCurve(line1);

    var tol = RhinoDocument.ModelAbsoluteTolerance;
    var ccx = Intersection.CurveCurve(curve0, curve1, tol, tol);

    A = ccx.Count;
    B = curve0;
    C = curve1;
  }

test_ccx.gh (3.5 KB)

– Dale

yes this would work and I have already implemented, but isn’t this a bug?! because the line was originally 100 times longer than the tolerance .

furthermore I don’t want to use CurveCurve method as I have to test the intersection against an infinite line segment, so now I am only scaling the line and it does the job, however this cannot be safe because the scale is relative to the tolerance and who knows what is the right factor

The Rhino SDK does not have a “simple” intersector that will compute the intersection of a curve and an infinite line. For this, you need Rhino’s full curve-curve intersector.

The Intersection.CurveLine method in RhinoCommon simulates an infinite line by extending the line throught the bounding box of the target curve. The line is then converted into a LineCurve and curve-curve intersection computed.

Does this help?

– Dale

1 Like

thanks for the clarification, it explains why the line length becomes zero when it is perpendicular to the curve. I suggest you include the line itself and the curve in the bounding box to avoid this issue.
as of now I am extending the line based on my application, but it would be great if that method is also become available in SDK.