C# how to project points to polyline (or curve)

Hi,

I want to project points to polyline the way picture shows. What is the optimal approach with rhinocommon in C#?
I found Intersection.ProjectPointsToBreps Method but I seem to have a problem implementing it. I was following logic of project point in grasshopper.


project points.gh (6.7 KB)

Regards,
Dan.

One way would be simply to create vertical lines through the points and intersect those with the polyline…

Yeah, I was thinking about that but since the grasshoper component is slow if I run this many (100+) times, I wasnt even trying that (I think I would get even slower performance).

try this
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Intersect_Intersection_RayShoot.htm

It needs

geometry

Type: System.Collections.Generic.IEnumerable<GeometryBase>
Only Surface and Brep objects are currently supported. Trims are ignored on Breps.

and it seems it wont accept polyline. It says only surface and brep are suppoerted. What exactly are breps? I feel like polyline isnt one.

Here is a the how and why to your question:

Implementing that in RhinoCommon, is just out of the box.

1 Like

Here I wrote a piece of code to implement what @Helvetosaur suggests.

var tol = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
var points = new List<Point3d>();
foreach(var pt in topChPts)
{
   var line = new Line(pt, -Vector3d.ZAxis);
   var x = Rhino.Geometry.Intersect.Intersection.CurveLine(botChPolyTemp.ToNurbsCurve(), line, tol, tol);
   if(x.Count > 0)
      points.Add(x[0].PointA);
}

ProjectPoints.gh (18.7 KB)

Thank you all guys,

Ive got it working.

So I went for what @Helvetosaur and @Mahdiyar proposed for now. I found it faster than ordinary curve curve intersect component in grasshopper. Anyways, I’ll be looking to some way of implementing more vectors to possibly make it faster. Ive been already tinkering with stuff @rawitscher-torres proposed.
project point2.gh (14.3 KB)