14.11 Rectangle to Oriented Box 669
14.11 Rectangle to Oriented Box
The algorithm for computing the squared distance between a rectangle and an ori-
ented box may be chosen similarly to that for a triangle and an oriented box. The
pseudocode is
float SquaredDistance (Rectangle rectangle, Box box,
float rClosest[2], float bClosest[3])
{
for (i1 = 0; i1 < 2; i1++)
{
float param1 = (2 * i1 - 1) * rectangle.e[1];
Vector3 delta1 = param1 * rectangle.axis[1];
for (i0 = 0; i0 < 2; i0++)
{
float param0 = (2 * i0 - 1) * rectangle.e[0];
Vector3 delta0 = param0 * rectangle.axis[0];
Vector3 corner = rectangle.C + delta0 + delta1;
if (PointInBox(corner))
{
tClosest[0] = param0;
tClosest[1] = param1;
Vector3f diff = corner - box.C;
for(j=0;j<3;j++)
{
bClosest[j] = Dot(box.axis[j],diff); ...