Simple Polyline Self-Intersection (RhinoCommon C#)

Very simple question: how can I solve for the self-intersection of a polyline with RhinoCommon?

In the attached, I am creating a polyline from a set of points, so it must (as far as I know) be explicitly cast as a polyline and not a curve. Solving for the intersection event with Rhino.Geometry.Intersect.Intersection.CurveSelf returns “Error (CS1503): Argument 1: cannot convert from ‘Rhino.Geometry.Polyline’ to ‘Rhino.Geometry.Curve’”

I’ve found solutions on the forum using RhinoScriptSyntax, but none with RhinoCommon.

PolylineSelfIntersect.gh (5.1 KB)

Cast it to nurbscurve, as long as the function asks for a Curve give it a curve, C# wont do it by itself :

Polyline newPoly = new Polyline(x);
var interEvent = Rhino.Geometry.Intersect.Intersection.CurveSelf(newPoly.ToNurbsCurve(), 0.001);
Point3d interPt = interEvent[0].PointA;

A = interPt;

Thanks. That’s perfect.

I’ve been having a bit of trouble understanding the relationships between all the different geometry types (especially all the Line, Curve, Polyline, Polycurve, PolylineCurve, etc.), but I think I’m starting to get it: because NurbsCurve inherits from Curve, it will work in Intersection.CurveSelf(), but because Polyline inherits from Point3dList it’s incompatible (it’s basically just a representation of a list of points). Please let me know if I have this right…

Thanks again Petras1!

that is correct.

1 Like