How to convert a curve into a polyline by distances?

divide curve into polyline by distances v0.gh (18.7 KB)
Plugin: Flexibility

Is it possible to convert a NURBS curve into a polyline with segments of fixed but varying lengths (e.g., 2, 5, 2, 5…) using only native components?

I can do that with Flexibility plugin, like here I turned a nurbs curve into a polyline which has repeating segments(3-6-9-3-6-9…)


I guess you need some sort of loop to get to that (and I believe that is what the Flexibility component is doing [I think also the standard gh component Divide Distance is doing the same, just without the option to use multiple distances])

with the 15% knowledge of Python I have, I would script it like this:


polyline_variable_segment lengths.gh (10.1 KB)

2 Likes

No script, but this is how I would approach it:

  1. Divide curve by length in subcurves of [9 + 6 + 3]= 18
  2. Divide every subcurve in subcurves of [9+6} =15. (the last second part of subcurve gives all the 18 - 15 = 3 parts
  3. Use all the first subcurves (15 long) from step 2 divide them in subcurves of [ 9], giving you the parts with length 9 and length 6

So for every length you need 9, 6 and 3 you need a division in subcurve starting at the correct point.

NB: You could of course first do the 3 divisions giving you all the t-parameters and cut all the subcurves in one move.

NB1. Just after saving the answer another approach rises in my mind.

  • calculate the greatest common divisor (in this case 3, because 3 can divide 3, 6 and 9)
  • divide the curve in subcurves with length of 3
  • use a short list 1, 2, 3 tot join subcurves of 3 to lenghs (1x3) (2x3) and (3x3)
    (off course also possible with floating point numbers)

PS; All thought from dividing by length. Dividing by distance will probably give incorrect numbers. (I will think further about doing simular with distances and polylines)

Regards, Eef

When cutting to a polyline using divide curve, it is inevitable you have some iterative process, where every next step start with the endpoint of the step before.
It also matters if it is a repeated pattern and it also matters with what number you start or the order of the 3 numbers.

Maybe I may do a suggestion to make the challenge more challenging.
Image you have a curve and have to transform it to a polyline with as less line-sections as possible. Line sections may have the length of 3, or 6 or 9.
And the greatest distance between curve and line-section may at any point be not more then x
That would give a great algorithm for building curves with standard pipes/staves

for a random curve, division by Length is a whole different story than division by distance :slight_smile:

1 Like

Thank you! I guess Surface | Curve intersection and loop are hard to avoid. I did make it with K2’s Line Length goal but that returns slightly inaccurate length when the curves are overly complex. And of cause, slow.

Thank you! I couldn’t understand your method. Would you please show a GH definition of that?

I think you can achieve this by using Kangaroo. Kangaroo is of native components now.

Which method are you referring to? I mentioned more then one.
BTW: Thinkering about it, does not mean I already have a working example :wink:
I will have to search myself to find a way to get there.

After “thinking” another hour or so, I cannot imagine a solution without any kind of loop.
One option I considered was to divide the curve in many points; find all points on the distances 3, 6 and 9. Find the most close points in the 3 list + 6 list; use the result to find most close points in the 9 list. In case it would work, if would need a lot of computer capacity to get a bit accurate result. millions of options would have to be calculated and culled afterwards. Not very usefull.
So I give up, and am interested in other ideas.