For calculation of centroid of quadrangle, points need to be sorted in order of their occurrence along the quadrangle's perimeter. Having 4 points p1, p2, p3, p4 with coordinate x, y for each such point, so with p1.x, p1.y, p2.x, ... what is the most efficient way to sort points along perimeter?
Formula or algorithm in any programming language is welcome, Javascript is preferred.