3

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!

Dre
  • 4,298
  • 30
  • 39

2 Answers2

3

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.

Vincent Mimoun-Prat
  • 28,208
  • 16
  • 81
  • 124
  • 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
1

Volumetric kd-trees?

Gareth Rees
  • 64,967
  • 9
  • 133
  • 163