Sorting polygon's points

前端 未结 2 709
南旧
南旧 2021-01-04 11:08

I have a convex polygon ABCDE... (it can have any number of points). I need to sort all its vertexes so none of the edges will intersect.
example:

A ____         


        
2条回答
  •  感情败类
    2021-01-04 11:23

    choose two points on the polygon. the midpoint of the line will be contained within that polygon. Let that point be M.

    Then, sort the points based on the angle based from M (along the X axis), breaking degeneracy based on distance from M. Iterating in that order ensures that no two edges will intersect.

提交回复
热议问题