How explode a curve into segment and find the length of them

Hi !

I’m trying to create a new component for grasshopper. To do it, I use Visual Studio community 2017 and C#.

I’m looking for a solution to explode a curve into multiple segment and then find the length of these segments.

Someone know how to do it ? I can’t find the right syntax…

Thanks a lot.


Explode how? You want individual spans, or split the curve at discontinuities? Or explode a polycurve into subcurves?

ps. You can measure the length of the sub-domain of a curve, there’s no need to explode the curve into new curves just to measure lengths.

My final goal is to measure the lengths of segments of a polygon. If you think there is no need to explode the polygon it’s perfect!
What syntax should be applied to achieve this ?

Is it for learning?
Why not use the built in explode component + curve length?
Or am I misunderstanding the question?

Polygons are fairly easy because they are polylines, and polylines are made up of line segments, and those have a Length property. It’s also easy to figure out how many segments a polyline consists of: polygoncomponent.cs (2.1 KB)

It’s to add a new component to a plugin. So I can’t use grasshopper component. I have to use C# and visual studio.
Sorry my english is not really good…

Thank you very much David !

@DavidRutten @Le_Pallier I wish to get the line length using GHPython. I am unable to proceed right now.

polyline1 = rg.Rectangle3d.ToPolyline(rect1)
polylineseg1 = rg.Polyline.GetSegments(polyline1)
polylineseg2 = polylineseg1[1]

I want the length of the line segments.

Thanks in advance.

Try to translate this to P. (9.5 KB)

1 Like

Here’s one approach: (6.6 KB)

1 Like
Curve[] segments = inputCurve.DuplicateSegments();

// calculate the length of each segment and add it to a list
List<double> segmentLengths = new List<double>();
foreach (Curve segment in segments)