how to order vertices in a simple, non-convex polygon

后端 未结 4 1153
离开以前
离开以前 2020-12-21 23:06

I have a problem where I have a series of points for a simple, non-convex polygon (I hope I have the terminology correct). But the points are not necessarily in order (ie,

4条回答
  •  有刺的猬
    2020-12-21 23:17

    I'm thinking of an O(n^2) algorithm:
    Since you have the points in order that they are drawn (hopefully), you know the endpoints of each edge.
    Choose a point to start on, then continue until you intersect another edge.
    Then you mark that spot, continue on the new edge until you reach yet another edge or an endpoint. Whenever you reach a point where you change edges, list it. Once you reach the start point, you are done.

提交回复
热议问题