Reputation: 4329
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!
Upvotes: 3
Views: 136
Reputation: 28541
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.
Upvotes: 3