Graphics Reference
In-Depth Information
P
Q
P
Q
B
B
(b)
(a)
Figure 5.3 Clamping P to the bounds of B gives the closest point Q on B to P : (a) for an edge
Voronoi region, (b) for a vertex Voronoi region.
for(inti=0;i<3;i++) {
float v = p[i];
if (v < b.min[i]) v = b.min[i];
// v = max(v, b.min[i])
if (v > b.max[i]) v = b.max[i];
// v = min(v, b.max[i])
q[i] = v;
}
}
In CPU architectures supporting SIMD instructions this function can often be
implemented in just two instructions: a max instruction followed by a min instruction!
5.1.3.1 Distance of Point to AABB
When the point Q on an AABB B closest to a given point P is computed only
to determine the distance between P and Q , the distance can be calculated with-
out explicitly obtaining Q . This is illustrated by the following code. To simplify
the calculation and to avoid an expensive square root call, the squared distance is
computed.
// Computes the square distance between a point p and an AABB b
float SqDistPointAABB(Point p, AABB b)
{
float sqDist = 0.0f;
 
Search WWH ::




Custom Search