Basically I have a list of points, each with X,Y,Z (Z is always the same).
For example:
pointList.add(Point p = new Point(1, 2, 3));
however I am having trouble sorting them into a clockwise order.
I know the centre and I know the there are roughly 600 points in each list.
I have accomplished this before in Python, but I am having trouble in C#.
Python code:
pointlist.sort(key=lambda c:atan2(c[0], c[1]))
Not sure if this would accomplish what you need.
points = points.OrderBy(x => Math.Atan2(x.X, x.Y)).ToList();
Not very optimized or anything, just looked at your python code and thought this would accomplish the same.
Note: You may need using System.Linq
unless you already have it.
Edit:
Sturm pointed out that reversing the order might be necessary to get them 'clock-wise'
One way of accomplishing this is using OrderByDescending
instead of OrderBy
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With