Closest polyline segment index


#1

Hi,

What would be the shortest way to get following:

  1. I have a point
  2. I have a polyline
    I need to know the closest line segment in polyline.

Is there something similar in RhinoCommon?
Or do I need to measure distance between all segments in polyline and take shortest one?


#2

If I recall correctly, this is this method you want:

http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Polyline_ClosestParameter.htm

Where the integer part of the returned parameter corresponds to the segment index and the decimal part the t value along it.

Edit: Just checked, seems to be it:

180321_PolylineClosestParam.gh (11.8 KB)


#3

Nice it outputs parameter with inteteger as segment id.
I remember you mentioned this before, but I did not put into my head.

Thank you Anders:)


#4

Haha, I had a strange sense of déjà vu as well. The Polyline class truly is a unsung hero of RhinoCommon :slight_smile: