10.4 Point to Polyhedron 397
qPrime.z = pPrime.z;
}
// If requested, compute the nearest point in global space (T^{-1})
if (computePoint) {
q.x = qPrime.x * box.u.x + qPrime.y * box.v.x + qPrime.z * box.w.x;
q.y = qPrime.x * box.u.y + qPrime.y * box.v.y + qPrime.z * box.w.y;
q.x = qPrime.x * box.u.z + qPrime.y * box.v.z + qPrime.z * box.w.z;
q += box.center;
}
return distanceSquared;
}
10.4.3 Point to Orthogonal Frustum
The material in this section is motivated in two dimensions in Section 6.3.3. The
algorithm for computing the distance from a point to an orthogonal frustum is based
on determining the Voronoi regions for the faces, edges, and vertices of the frustum.
Given a set of objects, the Voronoi region for a single object is the set of all points that
are closer to that object than to any other object. The Voronoi region containing the
point is computed. The nearest point on the frustum in that region is also computed.
From this the distance can be calculated.
The orthogonal view frustum has origin E. Its coordinate axes are determined by
left vector
ˆ
l, up-vector ˆu, and direction vector
ˆ
d. The vectors in that order form a
right-handed orthonormal system. The extent of the frustum in the
ˆ
d direction is
[n, f ], w h er e 0 <n<f. The four corners of the frustum in the near plane are E ±
6
ˆ
l ±µ ˆu +n
ˆ
d. The four corners of the frustum in the far plane are E +(f/n)(±6
ˆ
l ±
µ ˆu + n
ˆ
d). The frustum axis is the ray with origin E and direction
ˆ
d. The frustum is
orthogonal in the sense that its axis is perpendicular to the near and far faces.
Let P be the point whose distance to the frustum is required. The point can be
written in the frustum coordinate system as
P = E +x
0
ˆ
l +x
1
ˆu + x
2
ˆ
d
so x
0
=
ˆ
l ·(P −E), x
1
=ˆu ·(P −E), and x
2
=
ˆ
d ·(P −E). It is sufficient to demon-
strate the construction for x
0
≥ 0 and x
1
≥ 0. The idea is the same as in the 2D case:
reflect the x
0
and x
1
components, find the closest point, then reflect its x
0
and x
1
components back to the original quadrant.
The naming conventions for the frustum components are N for near, F for far,
U for up, and L for left. The top face of the frustum is labeled the F -face. It has two
edges: the UF-edge that is in the direction of
ˆ
l and the LF -edge that is in the direction