WIPIVERSE All articles

Sweep and prune

Sweep and prune (also known as sort and sweep) is a broad-phase algorithm used in collision detection for physical simulations and computer graphics. Its purpose is to reduce the number of pairs of objects that must be examined for intersection, thereby limiting the workload passed to more precise and computationally expensive narrow-phase tests.

Overview

In simulations involving many rigid bodies, checking every pair of objects for intersection is prohibitively costly, scaling quadratically with the number of objects. Sweep and prune addresses this by first approximating each object with a bounding volume — commonly an axis-aligned bounding box (AABB) — and then culling pairs whose bounding volumes cannot overlap. Only pairs flagged as potentially intersecting are forwarded to exact collision tests.

Method

The algorithm operates by projecting the bounding volumes onto one or more arbitrary axes. Along each axis, the starts (lower bounds) and ends (upper bounds) of the volumes are collected and sorted into lists. The algorithm then sweeps along the axis, and pairs whose intervals overlap along an axis are identified as candidate pairs. When the bounding volumes of two solids overlap along all tested axes, they are flagged for testing by more precise algorithms.

Sweep and prune exploits temporal coherence — the observation that objects generally do not move significantly between consecutive simulation steps. Because the sorted lists change only slightly from step to step, they can be updated with relatively few operations. Sorting algorithms that perform well on nearly sorted lists, such as insertion sort, are particularly suited to this task.

Bounding volume considerations

Depending on the type of bounding volume used, the volume's dimensions may need to be recomputed whenever an object is reoriented. Temporal coherence can be used to compute changes in bounding-volume geometry with fewer operations, or alternatively, orientation-independent bounding volumes such as bounding spheres may be employed.

Naming and history

The technique was referred to as sort and sweep in David Baraff's 1992 Ph.D. thesis, Dynamic Simulation of Non-Penetrating Rigid Bodies (Cornell University). Later work, such as the 1995 I-COLLIDE paper by Jonathan D. Cohen, Ming C. Lin, Dinesh Manocha, and Madhav K. Ponamgi, used the term sweep and prune. The method is treated in standard references on the subject, including Christer Ericson's Real-Time Collision Detection (2005).

Performance characteristics

The algorithm is output-sensitive: its cost depends on the number of objects and the number of overlapping pairs rather than on the square of the object count. It is therefore most advantageous in scenes that are sparse (few actual overlaps) and temporally coherent, and it is commonly cited as a suitable broad-phase approach when objects can be well approximated by axis-aligned bounding boxes and frame-to-frame movement is small.

Related concepts

Sweep and prune is one of several broad-phase strategies in collision detection, alongside spatial partitioning methods such as uniform grids, octrees, and bounding volume hierarchies. In real-time simulation frameworks such as Bullet and SOFA, variants of the algorithm are implemented as collision-detection components.

Browse

More topics to explore

    Browse all articles