Search code examples
wpfsortingdrawpolygon

How to draw a polygon from a set of unordered points


Currently, I am using a convex hull algorithm to get the outer most points from a set of points randomly placed. What I aim to do is draw a polygon from the set of points returned by the convex hull however, when I try to draw the polygon it looks quite strange.

enter image description here

My question, how do I order the points so the polygon draws correctly?

Thanks.

EDIT:

Also, I have tried sorting using orderby(...).ThenBy(...) and I cant seem to get it working.


Solution

  • Have you tried the gift wrapping algorithm ( http://en.wikipedia.org/wiki/Gift_wrapping_algorithm)? This should return points in the correct order.