Graphics Reference
In-Depth Information
A
P
r
Figure 4.5 AABB of the bounding sphere that fully contains object A under an arbitrary
orientation.
the direction vector. This distance can be computed through the projection of the
vertex vector onto the direction vector. For comparison reasons, it is not necessary
to normalize the direction vector. This procedure is illustrated in the following code,
which finds both the least and most distant points along a direction vector:
// Returns indices imin and imax into pt[] array of the least and
// most, respectively, distant points along the direction dir
void ExtremePointsAlongDirection(Vector dir, Point pt[], int n, int *imin, int *imax)
{
float minproj = FLT_MAX, maxproj = -FLT_MAX;
for(inti=0;i<n;i++) {
// Project vector from origin to point onto direction vector
float proj = Dot(pt[i], dir);
// Keep track of least distant point along direction vector
if (proj < minproj) {
minproj = proj;
*imin = i;
}
// Keep track of most distant point along direction vector
if (proj > maxproj) {
maxproj = proj;
*imax = i;
}
}
}
 
Search WWH ::




Custom Search