| |
|
|
||||
![]() |
||||||
| |
|
|||||
|
A Sphere-Sphere Sweep Test Figure 2 shows two spheres that collided between frames. If these spheres experienced acceleration during the frame, their trajectories will be second or higher order curves; however, usually their paths can be accurately approximated as linear segments according to the equations
Since both spheres traveled for the same amount of time, u is the same for both trajectories. The square of the distance between the lines is
and to calculate when they first make contact, we must solve for u such that
This leads to the quadratic equation
The vector vba can be thought of as the displacement of B observed by A. This equation is quadratic in u, so there may be no solution (the spheres never collided), one solution (they just glanced each other), or two solutions (in which case the lesser solution is when they began to overlap and the greater is when they became disjoint again). Again, it is a good idea to check for overlap at the beginning of the frame, since this will handle the case of two stationary spheres. Listing 2 shows an implementation of the sphere-sphere sweep test. Listing 2. The sphere-sphere sweep test. #include "vector.h" template< class T > inline
void SWAP( T& a, T& b ) {
const T temp = a; } // Return
true if r1 and r2 are real {
} const
bool SphereSphereSweep ) {
const VECTOR va = A1 - A0;
}
|
|
|