سؤال

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).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top