0

I have a set of convex polygons with a moderate number of sides (say from 4 to 30). There are a few tenths of polygons, say 100 to 1000. Most of them are isolated but a few form small groups of 2 to 10 that overlap between them.

I need to efficiently identify those groups of overlapping polygons.

Is there a classical algorithm ? (I am thinking of a sweepline approach but maybe there's better ?) Would it be beneficial to enclose the polygons in boxes before the detection ?

Below, a representative case.

enter image description here

1 Answers1

0

One traditional approach that's used for this kind of problem in two dimensions is to build a quadtree, which hierarchically divides your 2D space into successively smaller buckets until you have a small number of objects in each bucket.

Your overlap detection would walk the quadtree until you found the bucket or set of buckets that were intersected by your object, and then you would perform your overlap detection against a smaller set of objects.

There's a simple introduction to building and using them for collision detection here: Quick Tip: Use Quadtrees to Detect Likely Collisions in 2D Space

A simpler but more computationally expensive approach would be to do something a bit like using a z-buffer to determine whether one polygon occludes another:

  • Assign each of your polygons a unique number (it's depth)
  • Rasterize each polygon to a buffer, checking each write to the buffer to see whether you've occluded a pixel that's already set. If so, the depth identifies which polygon you've occluded and the new value you write the polygon with which you have occluded it.
russw_uk
  • 1,267
  • 8
  • 10