Game Development Reference
In-Depth Information
The origin of the ray could be inside the sphere. This is indicated by
e 2 < r 2 . Appropriate behavior in this case would vary, depending on the
purpose of the test.
A.13
Intersection of Two Circles or Spheres
Detecting the static intersection of two
spheres is relatively easy. (The dis-
cussion in this section also applies to
circles—in fact, we use circles in the di-
agrams.) Consider two spheres defined
by centers c 1 and c 2 and radii r 1 and
r 2 , as shown in Figure A.9. Let d be the
distance between their centers. Clearly,
the spheres intersect if d < r 1 + r 2 .
In practice, we can avoid the square
root involved in the calculation of d by
checking that d 2 < (r 1 + r 2 ) 2 .
Detecting the intersection of two
moving spheres is slightly more di cult. Assume, for the moment, that
we have two separate displacement vectors d 1 and d 2 , one for each sphere,
which describe how the spheres will move during the period of time under
consideration. This is shown in Figure A.10.
Figure A.9
Intersection of two spheres
Figure A.10
Two moving spheres
We can simplify the problem by viewing it from the point of view of
the first sphere, considering that sphere to be “stationary” while the other
sphere is the “moving” sphere. This gives us a single displacement vector
d , computed as the difference of the two movement vectors d 2 d 1 . This
is illustrated in Figure A.11.
Let the stationary sphere be defined by its center c s and radius r s . The
radius of the moving sphere is r m . The center of the moving sphere is c m
at t = 0. Rather than varying t from 0 to 1 as described previously, we
normalize d and vary t from 0 to l, where l is the length of the total relative
displacement. So the position of the center of the moving sphere at time t
Search WWH ::




Custom Search