Game Development Reference
In-Depth Information
Let n M and d M be the normal and d value, respectively, of the line
equation for M; since L and M are parallel, they have the same normal:
n M = n . Since q is on M, d M can be computed as q n .
Now the signed distance from M to L measured parallel to n is simply
d − d M = d − q n .
This distance is obviously the same as the distance from q to q
. (If we
need only the distance and not the value of q
, then we can stop here.) To
compute the value of q
, we can simply take q and displace it by a multiple
of n :
Computing the closest
point on a 2D implicit
line
= q + (d − q n ) n .
(A.1)
q
A.2
Closest Point on a Parametric Ray
Consider the parametric ray R in 2D or 3D defined by
p (t) = p org + t d ,
where d is a unit vector, and the parameter t varies
from 0 to l, where l is the length of R. For a given
point q , we wish to find the point q
on R that is
closest to q .
This is just a simple matter of projecting one
vector onto another, which was presented in Sec-
tion 2.11.2. Let v be the vector from p org to q . We
wish to compute the result of projecting v onto d
in other words, the portion of q parallel to d . This
is illustrated in Figure A.2.
The value of the dot product v d is the value t
such that p (t) = q
:
Figure A.2
Finding the closest point
on a ray
t = d v = d ( q p org ),
q
Computing the closest
point on a parametric
ray
= p (t) = p org + t d = p org + ( d ( q p org )) d .
(A.2)
Actually, Equation (A.2), for p (t) computes the
point closest to q on the infinite line containing R. If t < 0 or t > l, then
p (t) is not within the ray R, in which case, the closest point to q on R will
be the ray origin (if t < 0) or endpoint (if t > l).
If the ray is defined where t varies from 0 to 1 and d is not necessarily
a unit vector, then we must divide by the magnitude of d to compute the
Search WWH ::




Custom Search