Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing whether a polygon is simple or complex

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

like image 328
Drew Noakes Avatar asked Oct 22 '10 23:10

Drew Noakes


People also ask

How do you know if a polygon is simple?

If no intersections are discovered, the polygon is simple. If it is not, the polygon can be viewed as a chain of two or more simple polygons, with neighboring polygons in the chain having only a finite number of corner points in common (Figure 7.20b). Each simple polygon in the chain can then be treated separately.

How do you check a polygon?

Count the number of times the line intersects with polygon edges. A point is inside the polygon if either count of intersections is odd or point lies on an edge of polygon. If none of the conditions is true, then point lies outside.

Is a complex polygon a polygon?

In computer graphics, a complex polygon is a polygon which has a boundary comprising discrete circuits, such as a polygon with a hole in it. Self-intersecting polygons are also sometimes included among the complex polygons.

How do you check if a polygon is inside another polygon?

Perform line intersection tests for each pair of lines, one from each polygon. If no pairs of lines intersect and one of the line end-points of polygon A is inside polygon B, then A is entirely inside B.


2 Answers

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.

like image 117
Reed Copsey Avatar answered Sep 26 '22 01:09

Reed Copsey


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.

like image 25
Amit Prakash Avatar answered Sep 23 '22 01:09

Amit Prakash