In collision detection, we want to do as little work as possible while maintaining a physically-consistent environment. ... The sweep-and-prune method relies on a special case of the Separating Axis Theorem. ...
Ideally, we would use some imaginary perfect broad-phase algorithm which gives us the exact set of colliding pairs of objects in O(n) time (where n is the number of colliding pairs). Then the narrow-phase would extract the necessary fine-grain collision information. Thus, no non-colliding pairs (false-positives) would fall through the broad-phase.
In practice, a broad-phase algorithm will return false-positives that serve to waste cycles in the narrow-phase. Our objective is to cull as many pairs from the set of n(n-1)/2 possible colliding pairs of rigid bodies as possible.
The important aspects of sweep-and-prune are:
There are two approaches to ... One is complex but has good worst-case behavior, and the other is simple but has bad worst-case behavior.
Mirtich [1] discusses the use of a hierarchical spatial hash table. ... Scheduling algorithm ... ...
The disadvantage of spatial hashing is the complexity of implementation, as compared to the simplicity of implementing the coordinate sorting approach.
... Construct start & end lists, formed from swept volumes of sphere motions ... Sort each with O(n) radix sort, (show state diagram), ... ... Maintain list of active spheres, ... ...
The coordinate sorting approach has the disadvantage of worst-case O(n2) behavior if all the objects are highly clustered along one of the sorting axes (see Figure 6 in Mirtich's paper [1]). To see why this is bad, imagine the size of the active list when sorting along an axis with highly-clustered bounds. For this reason, the spatial hashing approach is more desirable for its worst-case behavior. However, as pointed out my Mirtich [1], no spatial hashing scheme can cull as many pairs as coordinate sorting.
There are many issues to consider when choosing which approach to use: