Graphics Reference
In-Depth Information
float r;
// Radius
};
x | (x - [a + u[0]*s + u[1]*t]) 2<=r
// Region R =
, 0 <= s,t <= 1
struct Lozenge {
Point a;
// Origin
Vector u[2];
// The two edges axes of the rectangle
float r;
// Radius
};
Due to similarity in shape, lozenges can be a viable substitute for OBBs. In situ-
ations of close proximity, the lozenge distance computation becomes less expensive
than the OBB separating-axis test.
4.5.1 Sphere-swept Volume Intersection
By construction, all sphere-swept volume tests can be formulated in the same way.
First, the distance between the inner structures is computed. Then this distance is
compared against the sum of the radii. The only difference between any two types
of sphere-swept tests is in the calculation used to compute the distance between
the inner structures of the two volumes. A useful property of sphere-swept volumes
is that the distance computation between the inner structures does not rely on the
inner structures being of the same type. Mixed-type or hybrid tests can therefore
easily be constructed. Two tests are presented in the following: the sphere-capsule
and capsule-capsule tests.
int TestSphereCapsule(Sphere s, Capsule capsule)
{
// Compute (squared) distance between sphere center and capsule line segment
float dist2 = SqDistPointSegment(capsule.a, capsule.b, s.c);
// If (squared) distance smaller than (squared) sum of radii, they collide
float radius = s.r + capsule.r;
return dist2 <= radius * radius;
}
int TestCapsuleCapsule(Capsule capsule1, Capsule capsule2)
{
// Compute (squared) distance between the inner structures of the capsules
float s, t;
Point c1, c2;
float dist2 = ClosestPtSegmentSegment(capsule1.a, capsule1.b,
capsule2.a, capsule2.b, s, t, c1, c2);
 
Search WWH ::




Custom Search