Graphics Reference
In-Depth Information
Y
P
1
Q
O
1
X
Fig. 12.11. Q is the reflection of P in the line.
r
Y
v
P
q
C
c
p
l v
s
q
t
X
Z
T
Fig. 12.12. The vectors required to locate a possible intersection.
12.11 Calculate the Intersection of a Line and a Sphere
In ray tracing and ray casting it is necessary to detect whether a ray (line)
intersects objects within a scene. Such objects may be polygonal, constructed
from patches, or defined by equations. In this example, we explore the inter-
section between a line and a sphere.
There are three possible scenarios: the line intersects, touches or misses the
sphere. It just so happens, that the cosine rule proves very useful in setting
up a geometric condition that identifies the above scenarios, which are readily
solved using vector analysis.
Figure 12.12 shows a sphere with radius r located at C . The line is rep-
resented parametrically, which lends itself to this analysis. The objective, of
which, is to discover whether there are points in space that satisfy both the
line equation and the sphere equation. If there is a point, a position vector
will locate it.
The position vector for C is
c = x C i + y C j + z C k
and the equation of the line is
p = t + λ v
 
Search WWH ::




Custom Search