Order segments consistently

Hi,
I have been struggling with the issue for a long time. Hope someone can help me: How to control the order of segments in a reference polyline.
The shape might change sizes (I get the drawing from the client) and I need to build based on it. The thing is I use segments from the drawing and I wish to have it consistently in the same order.
I try to sort the segment by distance to a ref point, and it works well, till one drawing broke the order because of its dimensions… see GH file attached.
Any other ways to make it bullet proof?
Is there a way to make it happen?
Cheers.


order segments.gh (9.4 KB)

The bottom line of what I am wishing for is that when I use item list on the segments Index 0 will always point to the same segment, no matter who draws the polyline, and no matter its dimensions. and the same Index 1 will always be the same element (let’s say the upper one would be 0, and the one next to it 1, and so on…). Hope it is clear …
Thanks.

What about setting Startpoint of curve (Curve Seam).
There is a seam component (input is parameter)
use a boundingbox to get a good reference point - depends a bit on the geometrical variations you expect …

And check / change Orientation: clockwise counterclockwise
not sure if nativ GH has it exposed. EDIT: yes: flip curve with parameter guide
Rhinocommon / c#-script can do it
https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.curve/closedcurveorientation

1 Like

Hi, thanks.
I tried with the seam, and with a guided Flip Curve, but it does not give a consistent solution…
I am not familiar with c# …

Hi,
Did you try the “sort along curve” component ?
Using a boundingbox, you should be able to extract the guide line…

can you post a collection of curves please ?
what is the sorting-order you re after, what is the rule for the starting index 0 ?

I posted in the first place a code that shows the issue: an octagon that I got from a client, and I need to use a few segments of it to build a geometry, so let’s say, I need to choose the upper segment with the two small segments next to it. In each octagon I got the client drew it differently and the order is different.
So I am looking for a method to make each segment with same index, so when I take segment X- and I know it is the upper segment and I can manipulate it, and when I want to rotate the upper left segment, I know it is in index Y.
I guess it is not so complicated, I just couldn’t make it work…

so all your curves have this kind of topology ? a rectangle that is chamfered ? = 8 side Polyline ?
always aligned to World x-y / parallel to x-y-axis ?

I’m just thinking, assuming you’re working on the XY plane, is the segment on the most North coordinate (+Y direction) before manipulation, also the segment with the most north coordinate even after the manipulation?

because if you are able to define segment “number zero” and then go on counting clockwise or counterclockwise, then you get what you are looking for

but first you need to find a way to define your starting segment, that will work perfectly whatever your starting scenario is

mm…I can get segment 0 by a ref point I am using anyway. (see the GH file) but How can you go counting clockwise or ccw ? This would be great help

this is just a sketch, uses a ton of components :slight_smile:

first flips the curves (in sucha way they are always CCW), then numbers segments starting with 0 for the one that has center point with greatest Y value

so by scaling them things should always fall into a good solution

if you also rotate the curve to be manipulated, then this logic won’t work at all

order segments_re.gh (12.4 KB)

[edit]

if you use a reference point that is not dependent on the geometries (like for instance a fixed point on XY plane) there are cases in which the closest point to that reference one will also change

2 Likes

Here is my proposition :


Sorting segments.gh (8.0 KB)

2 Likes

@inno Cool approach! I modified it a little and that seems to work fine at the moment! thanks!
Hope I won’t get any model that will break it…
Cheers!

1 Like

Seems like a good solution @Baptiste , thanks for that approach, didn’t know that sort along curve component… I will try to implement it in my code and see how it goes.
Cheers