Remember the elementary combinatorics problem "if each person at a party shakes hands with everyone else, how many handshakes are possible"? Well, this is the same as the worst case for collision detection. The maximum number of collisions (or handshakes) between n objects is n(n-1)/2, which is on the order of n2. Figure 1 illustrates the maximal interactions between five objects, which indeed add up to 5(4)/2=10.
![]() Figure 1: Maximal interactions between five objects |
This is bad, but how bad? To get some idea, we'll study the simplest system: a world made of spheres 1. We test for collision by comparing distances to the sum of the radii. The test itself can be reduced to a constant number of operations involving only a few multiplications and additions. But in the worst case, we have to do O(n2) tests, which doesn't scale gracefully to large numbers of spheres. Put simply, we're screwed if our environment allows the maximal number of collisions to occur.
In practice, our worlds are populated so that the worst case doesn't occur. I'd like to emphasize that if an environment is constructed in which every object collides with every other object, there's no way around the O(n2) computational complexity. So whatever we do, we must avoid this at all costs.
Assume for now we've lifted the O(n2) worst-case curse and got our engine scaling to tens of thousands of rigid bodies. Most physics SDKs have done exactly this and thus scale to very complex scenes; however, there's the problem of user-supplied collision-handling callbacks.
This is one way around the worst-case scenario and is just good form anyhow. The physics engine should provide a setting that does "panic mode" low-accuracy simplified collision detection. The idea is that it's better for the physics simulation to look terrible than for it to run at single-digit framerates. But we need to make sure the simulation is plausible (i.e., players can't fall through the ground, etc.).
What we want then is conservative collision detection. We do this by over-approximating collisions through the use of simpler geometries that bound the rigid bodies. The advantage is that we don't incur the expense of the narrow-phase. The disadvantage is that false positives are a guaranteed side-effect. This can result in unrealistic "explosions" in scenes that behave correctly before the narrow-phase is deactivated2. But then, which is more jarring—single-digit framerates or unrealistic physics?
Some ways to degrade collision detection & response gracefully:
Now that we've explored conservative collision detection, we'll look at an alternative. ... (reference to Mirtich's scheduling algorithm in "Efficient Algorithms for Two-Phase Collision Detection") ... ... use this scheduling algorithm to do collision tests less frequently for complex objects and more frequently for simple objects ... ... discuss tradeoffs ...
See Also:
Sphere Collision Test Without a Square Root
Sweep-and-Prune