Developer
Apr 12, 2013 at 10:31 PM
Edited Apr 12, 2013 at 10:38 PM

The points are not sorted because in the general ndimensional case there is no notion of sorting the points clock or counterclockwise.
The sorting in the 2D case can be done easily using the ConvexHull.Faces field. What you do is to start with the first face and then traverse all of them using the Adjacency.
The code should look along these lines:
var pivot = faces[0];
var sortedPoints = { pivot.Vertices[0] };
var previous = pivot;
var current = pivot.Adjacency[0];
while (current != pivot)
{
if (current.Vertices[0] == previous.Vertices[1])
{
sortedPoints.Add(current.Vertices[0]);
current = current.Adjacency[0];
}
else
{
sortedPoints.Add(current.Vertices[1]);
current = current.Adjacency[1];
}
previous = current;
}
EDIT: thinking about it, even a simple version that looks like this should work due to how the vertices are (should be :)) ordered inside the edges. Also I might have made a mistake in the adjacency indices. Tho it should be easy to figure out once you play
with it.
var pivot = faces[0];
var sortedPoints = { pivot.Vertices[0] };
var current = pivot.Adjacency[0];
while (current != pivot)
{
sortedPoints.Add(current.Vertices[0]);
current = current.Adjacency[0];
}
