Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if a polygon has self-intersections?

Imagine you have a 2D polygon (a 2D closed polygonal chain to be more precise). How do you check if it contains self-intersections? It can be convex or concave, oriented clockwise or counter-clockwise.

Now, I could just run a standard O(N log N) algorithm to check if any two segments cross. But I believe that because we have some additional structure -- the order of the segments and the fact that each two consecutive segments meet at endpoints -- a simpler and faster (maybe O(N)?) algorithm could be devised.

Any ideas?

like image 826
Jasiu Avatar asked Jul 21 '11 14:07

Jasiu


People also ask

Is polygon self-intersecting?

A polygon can be self-intersecting, meaning edges cross other edges. (The points of intersection are not vertices.) Regular polygons which are not self-intersecting are identified by an integer corresponding to the number of sides (or vertices) it contains.

What polygons that intersect itself?

Star polygon: a polygon which self-intersects in a regular way. A polygon cannot be both a star and star-shaped.

Does polygon have intersecting?

Polygons can intersect in three ways: Overlap—Area of overlap can be produced by leaving the Output Type to its default value (LOWEST). Common boundary/touch at a line—This type of intersection can be produced by specifying LINE as the Output Type.

Can a polygon have intersecting sides?

Polygons can have any number of sides and angles, but the sides can never be curved. The segments are called the sides of the polygons, and the points where the segments intersect are called vertices. Polygons can be either convex or concave.


1 Answers

Do you need just to check for self-intersections, or find all of them? The latter is harder than O(N log N), as you can have O(n^2) intersections with n segments.

If you only need to find out if self-intersections exist, or find a small amount of them, then look here. This paper seems to claim just what you need, particularly in the polygon planarization section. I doubt implementing the algorithm described there would be simple, or worthwhile for any problem of reasonable size. But such an algorithm does exist. Disclaimer: I haven't tried to work through the paper and understand it.

like image 53
n. 1.8e9-where's-my-share m. Avatar answered Jan 03 '23 01:01

n. 1.8e9-where's-my-share m.