Sorting vertices of a polygon in CCW or CW direction

I really need some urgent help with this problem.

I have a set of edges and vertices defining a polygon (not necessarily convex). The vertices and edges are in random order as shown in the image on the left. I want to sort/order the vertices of this polygon in clockwise (or anti-clock wise) direction, so that the desired output is as shown on the right.

       

 

Any idea how this can  be achieved?

Thank you!
-Prasad

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>