Take the 2-minute tour ×

I know how to check if a X,Y point is a single rectangular region, but say I have multiple regions that can potentially overlap ( the regions would have X,Y,Width,Height,Z-index ( or x1,y1,x2,y2 if that's easier -- I am not fussed on how I store that, if it's relevant )

Are there any efficient algorithms to determine if the point is inside one of the regions without having to iterate over every region.

I would prefer something without a long recalculation time when a region is added or removed, however that will be rarer then lookups.

Thank you!

share|improve this question
Are these rectangles aligned with the x- and y-axis? –  Bart Kiers Jan 20 '11 at 11:34
add comment

2 Answers

up vote 2 down vote accepted

You could store your regions into a Quadtree (or Octree if 3D). This would help you to reject most of the regions before getting into the real collision-test.

If you have multiple layers, simply have a quadtree per layer and use the relevant one according to the layer in which your point lies.

share|improve this answer
Thank you! That's exactly what I was looking for -- somehow I totally missed those in my own research! –  Dre Jan 20 '11 at 11:32
add comment

Your Answer


