Graphics Reference
In-Depth Information
2r = d + r 0 + r 1
d
C 0
C
C 1
r 1
r 0
Figure 6.5 Merging spheres S 0 and S 1 .
distance between the sphere surfaces; thus:
r 1 ) 2.
r
=
( d
+
r 0
+
The sphere center C is computed by adjusting C 0 by r 0 units away from C 1 and then
back toward C 1 by r units:
C 0 )
C 0 )
C
=
C 0
r 0 ( C 1
C 1
C 0 +
r ( C 1
C 1
C 0
C 0 )
=
C 0 +
( r
r 0 )( C 1
C 1
C 0
.
The code for this follows.
// Computes the bounding sphere s of spheres s0 and s1
void SphereEnclosingSpheres(Sphere &s, Sphere s0, Sphere s1)
{
// Compute the squared distance between the sphere centers
Vector d = s1.c - s0.c;
float dist2 = Dot(d, d);
if (Sqr(s1.r - s0.r) >= dist2) {
// The sphere with the larger radius encloses the other;
// just set s to be the larger of the two spheres
 
Search WWH ::




Custom Search