3 ms·
Overlap in multiple dimensions is simply the AND of overlap in each dimension. The 3D case comes up in collision detection. For collision detection in games,
by Animats 1y ago
Overlap in multiple dimensions is simply the AND of overlap in each dimension.
The 3D case comes up in collision detection.
For collision detection in games, the objects are usually kept in a sorted order, with separate lists for X, Y and Z. Amusingly, a bubble sort is useful, because, as objects move, they tend to move locally, so a bubble sort quickly restores the order. The sorting algorithm should terminate quickly when there are few or no changes. First seen in I-Collide, 1995. When objects are moving slowly, speed is slightly worse than O(N), but degrades if there's too much motion.
2D sorting speeds things up. If you sort the intervals by start X, start Y, you can process the intervals sequentially. Here's something of mine which does that.[1] A MySQL database does the sort, then feeds the data to this algorithm. Overlaps are detected, sets of overlapping objects are merged, and the sets of overlapping 2D rectangles are emitted. Sort is O(N log N) as usual, and overlap detection is O(N).
[1] https://github.com/John-Nagle/maptools/blob/main/rust/src/generator/vizgroup.rs https://github.com/John-Nagle/maptools/blob/main/rust/src/ge...
- efavdb 1y ago>>Overlap in multiple dimensions is simply the AND of overlap in each dimension. Presumably just for boxes aligned with the axes (or some other condition?)? EG two lines can have x’s in common and y’s but not overlap if they are sloped at some angle.
- deleted 1y ago[deleted]
- animal531 1y agoHave you tried prefix-sum? In my game code I used the Nvidia key/offset sort for a long time, but I've since replaced that for all of my physics and spatial queries. There are cases where even though the sort executes more instructions that the size of the elements/code still fits into some Ln cache level and makes it faster, but in general the prefix approach comes out ahead.