Testing whether a polygon is simple or complex

2019-01-22 00:03发布

For a polygon defined as a sequence of (x,y) points, how can I detect whether it is complex or not? A complex polygon has intersections with itself, as shown:

example complex polygon image

Is there a better solution than checking every pair which would have a time complexity of O(N2)?

3条回答
ら.Afraid
2楼-- · 2019-01-22 00:24

There are sweep methods which can determine this much faster than a brute force approach. In addition, they can be used to break a non-simple polygon into multiple simple polygons.

For details, see this article, in particular, this code to test for a simple polygon.

查看更多
我只想做你的唯一
3楼-- · 2019-01-22 00:29

See Bentley Ottmann Algorithm for a sweep based O((N + I)log N) method for this. Where N is the number of line segments and I is number of intersection points.

查看更多
4楼-- · 2019-01-22 00:39

In fact, this can be done in linear time use Chazelle's triangulation algorithm. It either triangulates the polygon or find out the polygon is not simple.

查看更多
登录 后发表回答