Hi everyone,
I’m working with a collection of freeform curves in Grasshopper that vary in length and curvature. I need to translate these curves—without changing their geometry—so that the minimum distance between any two curves is at least a specified target value.
However, the curves are not in the right order. Sorting them by midpoint, start point, or end point, x or y value doesn’t work because the curvature causes the order to be incorrect.
Does anyone have guidance or sample code on how to properly sort these curves and then adjust their positions to ensure the desired minimum spacing?
Thanks in advance!
Kind regards
Raphael
curve_spacing.3dm (83.1 KB)
Draw a curve that includes them all, so sorting becomes easy.
Have you also a solution to sort without manually drawing a curve?
No, sorry I don’t have a solution.
Using the input of @leopoldomonzani I could find an automatic solution.
How it works:
NB: Important starting point: It is always possible to create a line like @leopoldomonzani used, because: - The curves do not intersect
So:
- used convex hull 3 times:
1x around all end+beginpoints to create area around all curves
1 x around end + 1 around all beginpoints creating two areas. THESE two areas are ALWAYS separated and will not overlap! (will let’s be a bit more modest: Probably not never overlap
)
- Use region difference two get a surface over all curves. And find all intersections between surface + curves.
This way we get a new set of curves, what are all much shorter, and can be sorted on X or Y direction, using the middle curve point
And next sort curves with this order.
NB: Because of the shape, the last curve was not included as curve. So I used the intersecting point to find the curve and inserted at the end.
curve_spacing.gh (14.6 KB)
PS: If all sorted midpoints are interpolated, you will find the curve @leopoldomonzani used.
3 Likes