Sorting a list of points in 2-D clockwise
The problem is not well-defined for arbitrary point clouds. Clockwise around which point? How to handle collinear points? Does the path of sorted points need to have certain properties, e.g. no self-intersection?
Here are some ideas, but they all have certain drawbacks:
- Pick a point $C$, such as the average of all points. Sort all points $P_i$ by the angle of $\overline{CP_i}$ to $\overline{CP_0}$. Problems: If the point cloud is not convex, the result may not correspond to any intuitive notion of clockwise order. How to order points with the same angle (collinear to $C$)?
- Find the shortest path that connects all points (travelling salesman problem). Sort by clockwise order in that path. Problems: Hard to compute for many points. Using heuristics may lead to self-intersections.
Apply a Delaunay triangulationFind the convex hull and sort by clockwise order in it. Problem: Some points may not be part of it.
In this specific case, I'd subtract the average/center from all points.
Then convert the remainder to polar coordinates.
Then sort by angle, but you'd still have to find a starting angle.
(I'd start with $\pi / 2$ and have $5$ as first point).
But as from earlier comments, this is not really a formal mathmatically correct method.