From: Benjamin Root <ben.root@ou...>  20110826 17:11:01

On Friday, August 26, 2011, Stan West <stan.west@...> wrote: > From: Benjamin Root [mailto:ben.root@...] > Sent: Friday, August 19, 2011 13:43 > > I have an arbitrary list of coordinates that I know represent the boundary of a polygon. Is there some sort of function from the contouring or path codes that would allow me to pass in that list and get back the resorted list with the path codes with it? > > Hi, Ben. Is it the order of the points around the polygon that is unknown, and is it unambiguous because the polygon is known to be convex? If so, I believe you could use part of the Graham scan [1] convex hull algorithm. The function you need would find the point P with the lowest Y coordinate, then sort the remaining points by the cosine of the angle they and P make with the X axis. After that, the list comprising P and the sorted points would need the path codes. > > If the polygon is concave but the order is somehow clear (e.g., a radial progression about the average coordinate), you might be able to adapt the method. I hope I understood your problem correctly and that this helps. > > [1] http://en.wikipedia.org/wiki/Graham_scan Actually, that might be useful. The current solution I have is to use the core contouring function in mpl to generate paths, but they doesn't seem to guarantee either clockwise or counterclockwise traversals. Does graham scan guarantee something like that? I need to calculate outwardfacing normal vectors. Ben Root 