how to order vertices in a non-convex polygon (how to find one of many solutions)

后端 未结 1 1430
囚心锁ツ
囚心锁ツ 2020-12-08 09:13

I have the same problem as here: how to order vertices in a simple, non-convex polygon but there is no solutions I can use.

I have coordinates of points and need to

相关标签:
1条回答
  • 2020-12-08 09:35

    First, find the center of the bounding box that contains all of your vertices. We'll call this point C.

    Sort your list of vertices based on each point's angle with respect to C. You can use atan2(point.y - C.y, point.x - C.x) to find the angle. If two or more vertices have the same angle, the one closer to C should come first.

    Then, draw your points in the order they appear in the list. You will end up with a starburst pattern that is non-intersecting and probably non-convex. Example:

    100 points randomly placed on a 400x400 pixel square

    0 讨论(0)
提交回复
热议问题