Graphics Reference
In-Depth Information
for(inti=0;i<3;i++) {
// For each axis count any excess distance outside box extents
float v = p[i];
if (v < b.min[i]) sqDist += (b.min[i] - v) * (b.min[i] - v);
if (v > b.max[i]) sqDist += (v - b.max[i]) * (v - b.max[i]);
}
return sqDist;
}
5.1.4 Closest Point on OBB to Point
Let B be an OBB given by a center point C ; three orthogonal unit vectors u 0 , u 1 , and u 2
specifying the orientation of the x , y , and z axes of B ; and three scalar values e 0 , e 1 , and
e 2 specifying the box halfwidths along each axis (Figure 5.4). In this representation,
all points S contained by B can be written as S
=
C
+
a u 0 +
b u 1 +
c u 2 , where
|
a
| ≤
e 0 ,
b
e 2 .
A point P in world space relates to its corresponding point Q
e 1 , and
|
c
| ≤
=
( x , y , z )in
the coordinate system of the OBB B as P
z u 2 . Given P , the
OBB-space coordinates can be solved for as follows. Only the derivation of the x
=
C
+
x u 0 +
y u 1 +
P
y
x
u 1
u 0
C
e 0
e 1
Figure 5.4 The point P , in world space, can be expressed as the point ( x , y ) in the coordinate
system of this 2D OBB.
Search WWH ::




Custom Search