i
i
i
i
i
i
i
i
814 17. Collision Detection
abooleanwasFALSE, then it becomes TRUE when one startpoint changes
place with one endpoint. This is also illustrated in Figure 17.11.
So we can create a sorted list of intervals for all three main axes and
use the preceding algorithm to find overlapping intervals for each axis.
If all three intervals for a pair overlap, their AABBs (which the intervals
represent) also overlap; otherwise, they do not. The expected time is linear,
which results in an O(n + k)-expected-time sweep-and-prune algorithm,
where, again, k is the number of pairwise overlaps. This makes for fast
overlap detection of the AABBs. Note that this algorithm can deteriorate
to the worst of the sorting algorithm, which may be O(n
2
). This can
happen when clumping occurs; a common example is when a large number
of objects are lying on a floor, for example. If the z-axis is pointing in the
normal direction of the floor, we get clumping on the z-axis. One solution
wouldbetoskipthez-axis entirely and only perform the testing on the x-
and y-axes [315]. In many cases, this works well.
Grids
While grids and hierarchical grids are best known as data structures for
ray tracing acceleration, they can also be used for broad phase collision
detection [1275]. In its simplest form, a grid is just an n-dimensional array
of non-overlapping grid cells that cover the entire space of the scene. Each
cell is therefore a box, where all boxes have the same size. From a high
level, broad phase CD with a grid starts with insertion of all the objects’
BVs in our scene into the grid. Then, if two objects are associated with the
same grid cell, we immediately know that the BVs of these two objects are
likely to overlap. Hence, we perform a simple BV/BV overlap test, and if
they collide, we can proceed to the second level of the CD system. To the
left in Figure 17.12, a two-dimensional grid with four objects is shown.
To obtain good performance, it is important to choose a reasonable grid
cell size. This problem is illustrated to the right in Figure 17.12. One idea
is to find the largest object in the scene, and make the grid cell size big
enough to fit that object at all possible orientations [315]. In this way, all
objects will overlap at most eight cells in the case of a three-dimensional
grid.
Storing a large grid can be quite wasteful, especially if significant por-
tions of the grid are left unused. Therefore, it has been suggested that
spatial hashing should be used instead [315, 1261, 1275]. In general, each
grid cell is mapped to an index in a hash table. All objects overlapping
with a grid cell are inserted into the hash table, and testing can continue
as usual. Without spatial hashing, we need to determine the size of the
AABB enclosing the entire scene before memory can be allocated for the
grid. We also must limit where objects can move, so they do not leave
these bounds. These problems are avoided altogether with spatial hash-