Hi there,
is there a way to get a closest point of a curve on a Rhino.Geometry.Line?
I know it works with a point, but as I understand a Rhino.Geometry.Line is to be treated more vector-ish if I may call it like that.
I thought about making a bounding box through all elements and use the option to get the Line’s extents, but this might not work in some cases for me because I would need to think outside the limitations of a bounding box.
Is the line to be considered as infinite?
If so, project the curve on a plane perpendicular to the line, and use the usual ClosestPoint method to retrieve the parameter.
public void LineCurveProximity(Line L, Curve C, out double tL, out double tC){
Plane plane = new Plane(L.From, L.Direction);
Curve C2 = (Curve) C.DuplicateShallow();
C2.Transform(Rhino.Geometry.Transform.PlanarProjection(plane));
double t;
C2.ClosestPoint(L.From, out t);
tC = t;
tL = L.ClosestParameter(C.PointAt(tC));
}
Your question is not about grasshopper, but it helps anyway: LineCurveProximity.gh (8.7 KB)
A Line is just a struct with two points. And it does not inherit from Curve, so it doesn’t have all the same properties and methods as other Curve-inherited classes, such as LineCurve, ArcCurve, NurbsCurve, etc.
To you your question, I’d just create a LineCurve from your Line and then use Curve.ClosestPoints to get the closest points between the two curves.