Determining polygon intersection and containment

Posted by Victor Liu on Stack Overflow See other posts from Stack Overflow or by Victor Liu
Published on 2010-06-10T19:44:16Z Indexed on 2010/06/10 20:03 UTC
Read the original article Hit count: 264

I have a set of simple (no holes, no self-intersections) polygons, and I need to check that they don't intersect each other (one can be entirely contained in another; that is okay). I can check this by simply checking the per-vertex inside-ness of one polygon versus other polygons.

I also need to determine the containment tree, which is the set of relationships that say which polygon contains any given polygon. Since no polygon can intersect any other, then any contained polygon has a unique container; the "next-bigger" one. In other words, if A contains B contains C, then A is the parent of B, and B is the parent of C, and we don't consider A the parent of C.

The question: How do I efficiently determine the containment relationships and check the non-intersection criterion? I ask this as one question because maybe a combined algorithm is more efficient than solving each problem separately. The algorithm should take as input a list of polygons, given by a list of their vertices. It should produce a boolean B indicating if none of the polygons intersect any other polygon, and also if B = true, a list of pairs (P, C) where polygon P is the parent of child C.

This is not homework. This is for a hobby project I am working on.

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about math