Graphics Reference
In-Depth Information
Q
t
n
n
R
P
Figure 5.1
Plane
π
given by
P
and
n
. Orthogonal projection of
Q
onto
π
gives
R
, the closest
point on
π
to
Q
.
If the plane equation is known to be normalized, this simplifies to
t
=
(
n
·
Q
)
−
d
,
giving:
Point ClosestPtPointPlane(Point q, Plane p)
{
float t = Dot(p.n, q) - p.d;
returnq-t*p.n;
}
The signed distance of
Q
to the plane is given by just returning the computed
value of
t
:
float DistPointPlane(Point q, Plane p)
{
// return Dot(q, p.n) - p.d; if plane equation normalized (||p.n||==1)
return (Dot(p.n, q) - p.d) / Dot(p.n, p.n);
}
5.1.2
Closest Point on Line Segment to Point
Let
AB
be a line segment specified by the endpoints
A
and
B
. Given an arbitrary
point
C
, the problem is to determine the point
D
on
AB
closest to
C
. As shown in
Figure 5.2, projecting
C
onto the extended line through
AB
provides the solution. If
the projection point
P
lies within the segment,
P
itself is the correct answer. If
P
lies