algorithmic modeling for Rhino
Hello Everyone,
I'm having trouble figuring out the best way to sort a list of points clockwise. These points are the vertices of a surface.
I've tried sorting the list based on the angles between the lines that join the centroid and the vertices, and a line between the centroid and a reference point, but this does not always work.
I'm basically looking for a C# equivalent of the sortAlongCurve component. Any help would be great!
Thank you!
Tags:
Sort Along Curve component with the boundary as curve guide. Flip that curve guide if neccesary.
This not work?
Hi Daniel,
I'm sorry I wasn't more clear. I am trying to create a component in Visual Studio in C# and I'm trying to figure out how to write code that works like the sort along curve component.
Oh xD
Then I think something like:
t = List of parameters(as double)
For each pt, Closest Point to curve -> t.add(cpt curve parameter)
array.sort(t as keys, points as object)
Sorting along a curve is harder than just sorting by angle. But in both cases you need to use the Array.Sort() overload which takes two arrays, one for the sorting keys and the other for the points.
Point3d[] points = ...;
double[] angles = new double[points.Length];
for (int i = 0; i < points.Length; i++)
angles[i] = Math.Atan2(points[i].Y, points[i].X);
Array.Sort(angles, points);
Edit... Daniel beat me to it.
Thanks David, Daniel. That worked!
Have some fun with these as well
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by