Sort points in clockwise order?
Given an array of x,y points, how do I sort the points of this array in clockwise order (around their overall average center point)? My goal is to pass the points to a line-creation function to end up with something looking rather "solid", as convex as possible with no lines intersecting. For what it's worth, I'm using Lua, but any pseudocode would be appreciated. Thanks so much for any help! Update: For reference, this is the Lua code based on Ciamej's excellent answer (ignore my "app" prefix): function appSortPointsClockwise(points) local centerPoint = appGetCenterPointOfPoints(points) app