Closest distance between two curves CurveCurveIntersection


How I can compute closest distance between two curves?

I use curve curve intersection, but it is sensitive to tolerance.
If I set tolerance to 10 it gives good result and if 100 it is way off.
Is there some sort of way of to set the tolerance so that always closest distance is taken? (19.7 KB)

Is this is the right method?

 private void RunScript(List<Curve> x, object y, ref object A, ref object B)
     double maxDistance, maxt0, maxt1,minDistance,mint0,mint1;
    Rhino.Geometry.Curve.GetDistancesBetweenCurves(x[0], x[1], 1000, out maxDistance, out maxt0, out maxt1, out minDistance, out mint0, out mint1); 
    A = x[0].PointAt(mint0);
    B = x[1].PointAt(mint1);
    C =  x[0].PointAt(maxt0);
      D = x[1].PointAt(maxt1);

Hi Petras, this method might work for you: (6.0 KB)

1 Like

Works like magic.

Do you know what is the difference between the two methods?
Is one faster than the other?

x[0].ClosestPoints(x[1],out p0, out p1);

1 Like

Afraid I don’t, but we could look up the source on GitHub. A quick performance comparison test might be faster though :wink:

1 Like