Optimize a path / straighten a path



I wrote a script to find the middle path in a room (i.e. a corridor in my case) and now I would like to optimize this path by straightening it.

The goal is to create ducts following the best path possible depending on geometrical constrains

I’m using the Voronoi node to get the “analogical” path but now I would like to get the fittest straight path.

Any suggestions?


Use Springs.Line.StraightenXY:


Could also look at engineering something using Line.ByBestFitThroughPoints, stopping at points which have three or more lines out of them.

1 Like

It’s not working in my case but it was a good option, thank you !


I’m note sure how to make it stops as you say, can you make an example or explain more specifically ?


Get your Curve start and endpoints.
Flatten the list and group common points (list.groupbykey where the list and key are the same.
Discard groups with less than three elements in them.
Find which lines in the first list have those points in them. Those are the branching points.
Now you can start with those curves and use a group curves method to find the polycurve from each branch point.

1 Like

All my groups contain only one item.
(i’ve checkd all of the list)


Group the start and end points, not the lines. :slight_smile: