简体   繁体   中英

Sorting a list of vertices of a polygon clockwise

Please note that I'm a beginner with polygons and spatial representation.

This is what I have:

I'm working on a C# project, and I have list of vertices (defined by a latitude / longitude), representing a closed polygon. The polygon can be convex or concave, and it can't have any "holes". These vertices are adjacent but can be clockwise, or anti-clockwise.

This is what I'd like:

I'd like to know how to determine if this list is clockwise or counter-clockwise, then sort the vertices in order to they were clockwise. I'm able to do the sort algorithm by myself, but I have no idea how to determine it the given list of vertices are CW or CCW.

Here's the solution: https://en.wikipedia.org/wiki/Curve_orientation#Orientation_of_a_simple_polygon

Works also for concave polygons, as pointed out in the "practical considerations" section (basically the middle point for the test needs to be the topmost and leftmost point).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM