Sort Lines

I want to sort the lines.
The number before / is the index of the current line, the number after / shall be the sorted index.
image (1.7 KB)

Here’s one way, you can reverse the list item output to flip the order if needed: (7.4 KB)


1 Like

Hi Michael

Thank you.
One thing I don’t understand is why sorting the mid-points along the boundary box polyline will result in sorted points?

You don’t have to use the boundary box polyline, you can use any line to sort the points along. Like if you draw a line from your original point index 3, to point index 2, that would give you a line you could use to sort along as well.

Closed curves (such as this bounding box) still have a start and an end point which means the curve has a direction to it.

The sort points along curves node queries the direction of the guide curve and “works its way” around that guide curve finding the next closest point until it has exhausted the list.

Here’s a little diagram, if you start at the x on the bounding rectangle curve and start going clockwise the first closest point is the upper left as it has the least distance to the guide curve, then you keep moving around the guide curve and get each next closest point by distance.

But like I said you could use a polyline, straight line, or even a circle. Sometimes you may even want a convex hull polyline to help sort a certain way.

1 Like