Game Development Reference
In-Depth Information
Adding this displacement to q to project onto the circle, we get
Computing the closest
point on a circle or
sphere
q
= q + b
d − r
d d .
= q +
< r, then q is inside the circle. What should we with this
situation? Should q
If
d
= q , or should we project q outwards onto the surface
of the circle? Particular circumstances might call for either behavior. If we
decide we wish to project the points onto the surface of the circle, then we'll
be forced to make an arbitrary decision on what to do in the degenerate
case where q = c .
A.5
Closest Point in an AABB
Let B be an axially aligned bounding box (AABB) defined by the extreme
points p min and p max . For any point q we can easily compute q
, the closest
point in B to q . This is done by “pushing” q into B along each axis in
turn, as illustrated in Listing A.1. Notice that if the point is already inside
the box, this code returns the original point.
i f
( x < minX )
{
x
=
minX ;
}
e l s e
i f
( x > maxX )
{
x
=
maxX ;
}
i f
( y < minY )
{
y
=
minY ;
}
e l s e
i f
( y > maxY )
{
y
=
maxY ;
}
i f
( z < minZ )
{
z
=
minZ ;
}
e l s e
i f
( z > maxZ )
{
z
=
maxZ ;
}
Listing A.1
Computing the closest point in an AABB to a point
A.6
Intersection Tests
The remaining sections of this chapter present an assortment of intersec-
tion tests. These tests are designed to determine whether two geometric
 
Search WWH ::




Custom Search