Graphics Reference
In-Depth Information
• Frequently the vector form of a computation generalizes naturally to n
dimensions, while the generalization of the coordinate form may not be
obvious (a nice example is the decomposition of a vector into a part par-
allel to a given vector u and a part that's perpendicular to u ; our formula
works in 2-space, 3-space, 4-space, etc.).
• Our programs become easier to read and debug when we write less code.
Programs written to reflect the vector description of computations are usu-
ally simpler.
We'll consider two more examples of the vector form of computation of inter-
sections: the intersection of a ray with a plane and with a sphere.
7.8.1 Ray-Plane Intersection
Let's intersect a ray, given by its starting point P and direction vector d (so that a
typical ray point is P + t d , with t
0), with a plane, specified by a point Q of the
plane and a normal vector n . A point X of the plane therefore has the property that
( X
Q )
·
n = 0,
(7.88)
which generalizes the standard implicit form of a line in R 2 .
We seek a value, t
0, with the property that the point P + t d is on the plane,
for this point will be on both the plane and the ray, that is, at their intersection.
Let's proceed by assuming that such an intersection point exists and is unique;
we'll return to this assumption shortly.
For P + t d to lie on the plane, it must satisfy
(( P + t d )
Q )
·
n = 0.
(7.89)
We can now simplify this considerably and solve for t as follows:
(( P + t d )
Q )
·
n = 0
(7.90)
( P
Q + t d )
·
n = 0
(7.91)
( P
Q )
·
n + t d
·
n = 0
(7.92)
·
n =
( P
Q )
·
t d
n
(7.93)
t d
·
n =( Q
P )
·
n
(7.94)
t = ( Q
P )
·
n
(7.95)
d
·
n
The reader will notice that this is essentially the same computation we did in
Equation 7.87 earlier; once again, the vector form generalizes nicely.
Inline Exercise 7.11: In the algebra shown above, why did we not write
P
·
n + t d
·
n
Q
·
n = 0 as a simplification of the first equation?
Knowing t , we can now compute the intersection point P + t d .Twosmall
concerns remain:
• The possibility of division by zero in the expression for t
• The assumption that an intersection exists and is unique
 
 
 
Search WWH ::




Custom Search