Graphics Reference
In-Depth Information
there are two real roots, with the spheres coming in first contact at the smaller time t
then interpenetrating for awhile to stop penetrating at the larger time t . The first time
of contact is for
b 2
=
b
ac
t
.
a
When implementing this test, it is necessary to verify that the spheres do not overlap at
the start of the movement. Otherwise, it would fail to correctly deal with, say, a smaller
sphere remaining fully inside a larger sphere, because the condition of the spheres
coming into contact will never be satisfied in this case. One way of implementing
this test is:
int TestMovingSphereSphere(Sphere s0, Sphere s1, Vector v0, Vector v1, float &t)
{
Vector s = s1.c - s0.c; // Vector between sphere centers
Vectorv=v1-v0; // Relative motion of s1 with respect to stationary s0
float r = s1.r + s0.r; // Sum of sphere radii
float c = Dot(s, s)-r*r;
if (c < 0.0f) {
// Spheres initially overlapping so exit directly
t = 0.0f;
return 1;
}
float a = Dot(v, v);
if (a < EPSILON) return 0; // Spheres not moving relative each other
float b = Dot(v, s);
if (b >= 0.0f) return 0;
// Spheres not moving towards each other
floatd=b*b-a*c;
if (d < 0.0f) return 0;
// No real-valued root, spheres do not intersect
t = (-b - Sqrt(d)) / a;
return 1;
}
An alternative description of this particular approach can be found in [Gomez99].
Another approach to the problem is to express it in terms of one solved earlier. First,
the problem (Figure 5.35a) is turned into that of a moving sphere versus a stationary
sphere, by subtracting v 1 off the movement of both (Figure 5.35b). Because the spheres
first come in contact when d ( t )
r 1 , growing the radius of one while shrinking
the radius of the other by the same amount does not affect the time of contact. It is
therefore possible to turn the moving sphere into a point and the second stationary
=
r 0
+
 
Search WWH ::




Custom Search