## Sweeping a sphere against a sphere

This is going to be quite a short post, since we did the bulk of the work in the last post, the extension to sphere-sphere is fairly trivial.

All that is required is to realize that the time of impact for a sphere swept against a sphere is the same as the time of impact for a sphere which is the sum of the radii swept against a point. The contact point is simply the point along the normal at the perimeter of the sphere we swept against.

public static bool Sweep(BoundingSphere sweepSphere, BoundingSphere otherSphere, Vector3 direction, out SweepResult sweepResult) { //like a sphere-point sweep with a sphere the size of the sum of the radii sweepResult = new SweepResult(null); BoundingSphere infSphere = new BoundingSphere(sweepSphere.Center, sweepSphere.Radius + otherSphere.Radius); SweepResult infSweepResult; //Inflated sphere result bool infResult = SweepSpherePoint(infSphere, otherSphere.Center, direction, out infSweepResult); sweepResult.T = infSweepResult.T; if (infSweepResult.T != null) { sweepResult.Point = infSweepResult.Point + infSweepResult.Normal * otherSphere.Radius; sweepResult.Normal = infSweepResult.Normal; } return sweepResult.Intersection = infResult; }

Advertisements

## Leave a Reply