algorithmic modeling for Rhino
Hi eveybody,
i was hoping somebody could help me with the syntax for a rhinolist sort method.
what i have is a rhinolist (called "allPoints) of Point3d's, and another point (ill call it "testPoint") what i want to do is sort the "allPoints" list by their distance to "testPoint"
so far my best guess has been...
allPoints.Sort(testPoint.DistanceTo);
but clearly this isnt working.
ps. im working in C#
Tags:
Hi Mario,
RhinoList is very similar to System.Collections.Generic.List so the Sort function works in the same way.
You need to supply a sorting function in the form of an IComparer<T> which is an interface or Comparison<T> which is a delegate. There's actually a fair bit of code involved in doing this.
RhinoList however provides two additional overloads that allow you to sort using keys. So all you need to do is compute the distances as an array of doubles, then call the appropriate overload.
double[] distances = new double[allPoints.Count];
for (int i = 0; i < allPoints.Count; i++)
{
distances[i] = testPoint.DistanceTo(allPoints[i]);
}
allPoints.Sort(distances);
//Note, this code is untested.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Welcome to
Grasshopper
© 2024 Created by Scott Davidson. Powered by