Fact-checked by Grok 2 weeks ago

Sweep and prune

Sweep and prune (), also known as sort and sweep, is a broad-phase employed in , physics simulations, and virtual reality applications to efficiently identify potential intersecting pairs among a set of objects by projecting their axis-aligned bounding boxes (AABBs) onto spatial axes and eliminating non-overlapping candidates. The method reduces the naive O(N²) complexity of pairwise intersection tests—where N is the number of objects—by leveraging spatial and temporal to prune irrelevant pairs, typically achieving near-linear performance in practice for dynamic scenes. The algorithm operates in two main phases: a preliminary step that computes AABBs for all collision models in the scene, followed by a sweeping process that sorts the projected intervals along each principal axis (x, y, z). Overlaps are detected by scanning the sorted lists to find adjacent intervals that intersect; pairs overlapping in all three dimensions are flagged as potential colliders for subsequent narrow-phase verification using more precise geometric tests. This axis-by-axis decomposition simplifies 3D detection into manageable 1D problems, with sorting often optimized via insertion methods that exploit frame-to-frame object motion for O(N) updates rather than full O(N log N) resorts. SAP has been enhanced for large-scale and dynamic environments, incorporating structures like segmented interval lists to support efficient insertion, removal, and batch operations without resorting the entire dataset, making it suitable for simulations with thousands of objects including many static ones. These improvements address challenges in and real-time applications, outperforming alternatives like octrees in temporally coherent scenarios while maintaining low memory overhead.

Overview

Definition and purpose

Sweep and prune (SaP), also known as sort and sweep, is a broad-phase collision detection algorithm designed to efficiently identify potential overlapping pairs among a set of moving or static objects in three-dimensional space. It achieves this by projecting the axis-aligned bounding boxes (AABBs) of objects onto the principal coordinate axes (x, y, z), sorting the resulting one-dimensional intervals, and then pruning pairs that do not overlap on at least one axis. This method leverages both geometric and temporal coherence—assuming objects move continuously and do not change drastically between frames—to maintain sorted lists incrementally, avoiding full resorting in each timestep. The primary purpose of sweep and prune is to reduce the computational complexity of collision detection from the naive O(n²) pairwise checks, where n is the number of objects, to approximately O(n + k) time, with k representing the number of potential colliding pairs (typically much smaller than n² in sparse scenes). By filtering out distant object pairs early, it enables subsequent narrow-phase exact collision tests (e.g., using separating axis theorems or feature-based methods) to focus only on promising candidates, making it suitable for real-time applications such as computer graphics, video games, robotics simulations, and virtual reality environments. This pruning step is particularly effective in dynamic scenes with hundreds to thousands of objects, where full pairwise evaluation becomes prohibitive. Introduced in the context of interactive multi-body simulations, sweep and prune addresses the bottleneck in large-scale environments by exploiting the low dimensionality of projections while preserving accuracy for AABB-based approximations. Early implementations demonstrated interactive rates, processing over 1,000 complex polytopes in under 1/20 of a second on mid-1990s , highlighting its scalability for architectural walkthroughs and deformable object interactions. Modern variants continue to build on this foundation, adapting it for and higher dimensions, but the core algorithm remains a staple for its simplicity and robustness in broad-phase .

Algorithm fundamentals

Sorting phase

The sorting phase of the sweep and prune algorithm begins by projecting the axis-aligned bounding boxes (AABBs) of all objects onto each of the coordinate axes—typically x, y, and z in —to reduce the problem to one-dimensional overlaps. For each object, this projection yields two endpoints per axis: the minimum and maximum coordinates of the AABB along that axis, representing the start and end of an . These endpoints are then collected into separate lists, one for each dimension, where each entry is tagged with the corresponding to track ownership. The core operation in this phase is these endpoint lists to establish a linear order of the projections. The algorithm sorts the endpoints in ascending order, distinguishing between minimum (left) and maximum (right) endpoints, often by using flags or separate structures to differentiate them. This enables efficient identification of overlapping intervals by "sweeping" a through the sorted list, as adjacent overlapping projections indicate potential collisions in that . In the original formulation, an is employed, which exploits temporal coherence in dynamic scenes—where object positions change incrementally between frames—to achieve expected average-case performance for n objects, rather than the O(n log n) of full sorts like . To handle multiple dimensions, the is performed independently on each axis's list, creating three sorted arrays. Overlaps are only considered for object pairs whose projections overlap in all dimensions simultaneously, which filters out non-intersecting pairs early. This phase must be repeated or updated each step to account for object motion, with optimizations like lazy resorting (only swapping adjacent misordered endpoints) preserving efficiency in coherent animations. Subsequent work has refined this by using priority queues or binary search trees for endpoint management, but the foundational projection-and-sort mechanism remains central to in large-scale environments.

Pruning phase

The pruning phase of the sweep and prune algorithm identifies potential colliding pairs of objects by detecting overlaps in their axis-aligned bounding boxes (AABBs) after the sorting phase has ordered the projections along each coordinate . This phase exploits the sorted lists of endpoints (minima and maxima) for each —typically x, y, and z—to efficiently prune non-overlapping pairs, reducing the computational load for subsequent narrow-phase collision tests. Two AABBs are considered potentially colliding only if their projections overlap on all three axes; otherwise, they are discarded. This dimension-reduction approach ensures that the algorithm avoids exhaustive pairwise checks, achieving near-linear in practice for coherent scenes. In detail, the process maintains a set of active pairs—those whose bounding boxes overlap in all dimensions—along with flags indicating overlap status per dimension for relevant object pairs. Overlap detection is integrated with the sorting updates: during the on each 's endpoint list, when two adjacent endpoints are swapped (due to object motion), the algorithm re-evaluates the overlap status on that for the two objects owning those endpoints and toggles the corresponding if necessary. A pair is added to the active set if all three flags become true (overlaps on x, y, and z), and removed if any flag turns false. This local, incremental approach leverages temporal coherence, avoiding full re-computation each frame. The resulting active pairs are forwarded to exact . Implementations often optimize this phase by using during updates for O(n) expected performance when object motions are small, and by employing pair managers to avoid redundant checks. For instance, in large-scale environments, box-pruning variants may supplement the sweep with brute-force overlap tests on reduced candidate sets to handle insertions and removals efficiently. This phase's effectiveness stems from its simplicity and adaptability, making it suitable for real-time applications like , where it can prune over 90% of potential pairs in clustered scenarios.

Implementation

Data structures

The sweep and prune algorithm relies on axis-aligned bounding boxes (AABBs) to represent the spatial extents of objects for collision detection. Each AABB is defined by six scalar values: the minimum and maximum coordinates along the x, y, and z axes, which bound the object's geometry conservatively. These coordinates are typically stored in a simple structure or array per object, allowing quick projection onto individual axes to form one-dimensional intervals [min, max]. This representation exploits the alignment with coordinate axes to simplify overlap tests, with updates to the AABBs performed incrementally as objects move or deform, recomputing extrema from vertices or using fixed-size approximations like bounding cubes for further efficiency. To enable the sorting and sweeping operations, the algorithm maintains three independent sorted lists—one for each axis—comprising projections of all n objects' AABBs. In the basic formulation, each list is a sorted array of 2n endpoints: the minimum and maximum coordinates along the respective axis for each object, with each endpoint including the scalar value, a reference or index to the owning object, and a flag distinguishing min from max. These endpoints are stored in arrays for cache-friendly access, with initial sorting in O(n log n) time via radix or merge sort, and maintenance via insertion sort that exploits frame-to-frame coherence for O(n) expected update time. Overlaps are detected by sweeping the sorted endpoint list: traversing from low to high while maintaining an active set of objects whose intervals contain the current position (adding an object on its min endpoint and removing on max), and identifying overlapping pairs by testing the new object against the active set upon encountering a min endpoint. For dynamic scenes requiring frequent insertions, deletions, or updates, advanced implementations augment the lists with hierarchical or segmented structures, such as node-based trees per axis, to avoid full resorting. Each node in these structures references minima and maxima, enabling localized adjustments while preserving overall sort order. An auxiliary active pair set, often implemented as a or list, stores object pairs that overlap on all three axes, passing them to narrow-phase detection. These designs balance memory usage (typically space) with query efficiency, scaling to thousands of objects in simulations.

Updating and maintenance

In dynamic simulations where objects move, deform, or are added and removed, the sweep and prune algorithm requires efficient mechanisms to update its sorted lists of axis-aligned bounding box (AABB) endpoints without resorting the entire dataset each frame, which would be computationally expensive at O(n log n) per update for n objects. Instead, persistent variants exploit temporal coherence by performing local adjustments: when an object's AABB changes position, its min and max endpoints are updated along each axis, and the affected entries are reinserted into the sorted list using insertion sort or by swapping with adjacent elements until the correct order is restored. This incremental approach typically costs O(k) time per object, where k is the number of swaps needed, often small due to limited motion between frames. For insertion of a new object, the algorithm computes its projections on all axes and inserts the six endpoints (min and max per axis) into the respective sorted lists using binary search to find the position followed by a shift or swap , achieving O(log n + m) time where m is the list length affected by the shift. Removal is analogous: locate the endpoints via object references and delete them, shifting remaining elements, also in O(log n + m) time. To handle large-scale scenes with frequent updates, segmented lists divide the sorted arrays into fixed-size blocks or a , allowing localized updates within segments and reducing global shifts; this structure supports of multiple insertions or removals, minimizing overhead in environments with many dynamic objects. Maintenance also involves periodic full resorts to correct accumulated errors from lazy updates, especially if motion is erratic, and stale overlap pairs from the candidate set after each sweep to prevent growth. In adaptive implementations, the update strategy switches dynamically based on object count and motion patterns—for instance, favoring segmented lists for mostly static scenes and batch resorts for high-dynamics—ensuring across CPU or GPU architectures with reported speedups of 5-6x on multi-core systems. These techniques maintain the algorithm's O(n log n + p) overall complexity per frame, where p is the number of potential pairs, while supporting performance in simulations with thousands of objects.

Variants and extensions

Dimensional adaptations

The sweep and prune algorithm, originally formulated for detecting interval overlaps in one dimension, adapts to higher dimensions by independently projecting axis-aligned bounding volumes onto each coordinate axis and performing overlap tests across all projections. In two dimensions, objects are represented by axis-aligned bounding rectangles, with endpoints sorted along the x- and y-axes separately; potential collisions are identified only for pairs whose projections overlap on both axes, reducing the number of exact intersection tests from O(n²) to O(n log n + k), where n is the number of objects and k is the number of overlapping pairs. This approach leverages the , ensuring that non-overlapping projections on any single axis prune impossible collisions efficiently. In three dimensions, the method extends naturally to axis-aligned bounding boxes (AABBs) by projecting onto the x-, y-, and z-axes, maintaining sorted lists for each and updating them incrementally to exploit temporal coherence between simulation steps. Overlaps are reported only if intervals intersect on all three axes, further culling candidates before narrow-phase checks; this is the standard adaptation in real-time graphics and physics simulations, achieving near-linear performance O(n + c) per frame under high coherence, where c is the number of endpoint swaps. The I-COLLIDE system exemplifies this in large-scale 3D environments with thousands of moving polytopes, processing over 1,000 objects in under 1/20 of a second on 1990s hardware by using insertion sort on projections. While generalizes to d dimensions by projections along each of d axes and requiring overlaps on all to flag candidates, its use beyond three dimensions is uncommon due to increasing overhead from additional sorts and the rarity of high-dimensional in practical applications like or . In such cases, the approaches O(d n log n + k), with effectiveness improving as d grows—since more axes provide opportunities for separation—but at the cost of higher and per object. Seminal formulations emphasize its scalability in and , where it balances simplicity and efficiency without assuming object motion constraints.

Parallel and optimized versions

Parallel versions of the sweep and prune algorithm address scalability challenges in large-scale simulations by leveraging multi-core CPUs and GPUs, enabling efficient broad-phase for millions of objects. These implementations typically parallelize the and pruning phases while incorporating optimizations to handle object clustering and temporal coherence. A key multi-core CPU approach divides the algorithm into three parallel stages: sorting endpoints with exploiting temporal coherence for load balancing, generating candidate pairs via dual-axis sweeping using a cache-friendly SuccTree data structure, and performing object pairing through adaptive partitioning that distributes long intervals across threads. To optimize for three-dimensional dynamic box intersections, this method dynamically selects the primary sweeping axis based on a measure, reducing bottlenecks in clustered scenarios. On 16-core systems, it achieves up to 16x speedup and processes 1 million objects in 122–167 ms, depending on density, outperforming prior CPU methods and rivaling early GPU implementations. For GPU acceleration, a CUDA-based variant integrates parallel sweep and prune into continuous pipelines, using to identify potential colliding sets from sorted endpoint lists across axes, combined with spatial decomposition for workload distribution across GPU clusters via MPI. Optimizations include stream-based processing of bounding volumes and dynamic load balancing by transferring cells between nodes, enabling culling for 100,000 entities in 300 ms on four GPU nodes, with a 2.6x over single-node GPU setups. Earlier parallel adaptations, such as a 2010 implementation on the Cell Broadband Engine, parallelize endpoint across three synergistic processing elements using vectorized SIMD insertion sorts that exploit temporal coherence, alongside a hash-based pair manager for efficient overlap tracking. This yields superior initial sorting performance over x86 equivalents for 512–1024 objects but incurs overheads in dynamic scenes with 10% moving objects, limiting interactive rates. Additional optimizations across platforms emphasize succinct bi-dimensional representations to reduce memory usage in and context-aware processing for , as seen in multi-core and multi-GPU frameworks that achieve 5.1x on eight cores and 4.2x on a single GPU for 20,000 cubes through threading and sequential handling.

Applications and performance

Use in collision detection

Sweep and prune serves as a broad-phase algorithm, primarily used to efficiently cull non-intersecting object pairs in dynamic environments before performing more computationally expensive narrow-phase tests. By projecting axis-aligned bounding boxes (AABBs) of objects onto the principal axes (x, y, z) and these projections, the algorithm identifies potential overlaps by sweeping through the sorted lists and pairs that do not overlap in all dimensions. This approach reduces the from O(n²) pairwise checks to O(n + k), where n is the number of objects and k is the number of potential colliding pairs, making it suitable for real-time applications such as and simulations. In the seminal I-COLLIDE system, sweep and prune is integrated as the initial filtering stage for interactive among hundreds to thousands of moving polytopes. The algorithm exploits temporal coherence by using on the axis projections, which maintains order efficiently when objects move incrementally between frames, achieving near-linear scaling. For instance, in benchmarks on an HP-9000/750 workstation, it processed over 1000 polytopes at interactive rates of up to 23 frames per second, trimming interactions to a manageable subset for exact narrow-phase detection using hierarchical bounding volumes. This framework demonstrates its robustness in handling dense scenes without assumptions on object velocities or accelerations. Modern physics engines and simulation frameworks widely adopt sweep and prune variants for broad-phase . In Physics, the btAxisSweep3 implementation uses array-based storage for 3D axis projections to detect overlaps among rigid bodies, supporting dynamic worlds with insertion and removal of objects. It is particularly effective for scenarios with moderately sized scenes, such as games, where it prunes pairs before GJK-based narrow-phase checks. Similarly, the SOFA framework employs DirectSAP, a sweep and prune method that sorts primitives along axes using AABBs, allocating memory once for efficiency in multi-body simulations like deformation. These implementations highlight its adaptability to both rigid and deformable object in real-time systems. The algorithm's strengths in lie in its simplicity and low memory footprint, requiring only sorted lists per , which enables easy parallelization and integration with other spatial structures. However, its effectiveness depends on object distribution; in highly clustered scenes, the number of reported pairs can approach O(n²), necessitating approaches with grids or for very large-scale environments. Despite this, sweep and prune remains a foundational technique due to its proven performance in interactive applications.

Advantages and limitations

Sweep and prune (SaP) offers several advantages in broad-phase , particularly in dynamic environments. Its is typically O(n + k), where n is the number of objects and k is the number of overlapping pairs, making it output-sensitive and more efficient than brute-force O(n²) methods for sparse scenes. The algorithm exploits both spatial , by projecting axis-aligned bounding boxes (AABBs) onto principal axes to quickly reject non-overlapping pairs, and temporal , through incremental updates that minimize resorting when objects move slightly between frames. This results in significant reductions in pairwise tests, enabling interactive rates such as 23 frames per second for 1,000 polytopes in rigid-body simulations. Despite these strengths, SaP has notable limitations, especially in scalability for large-scale applications. In environments with many objects, frequent endpoint swaps during incremental sorting can lead to super-linear performance degradation, approaching O(n^{2-1/k}) where k is the number of axes, due to dense interval lists dominating runtime. Insertion and removal of objects are inefficient without optimizations, requiring O(n) time for resorting, which hampers dynamic scenes with high turnover. Additionally, the reliance on conservative AABBs can generate excessive false positives in dense or high-velocity scenarios, where overlaps occur in all projections but not in 3D space, and performance drops to near-quadratic in worst-case stacked configurations. SaP is less suitable for static scenes or non-coherent queries like path planning, where spatial partitioning methods like grids or trees outperform it.

References

  1. [1]
    Detection Sweep and Prune - SOFA Documentation
    In this section, we describe the two collision detection methods based on the "Sweep and Prune" algorithm, noted SAP.
  2. [2]
    Sweep and Prune
    Given a number N of objects, O(N2) object pairs have to be checked for collision. In general, the objects in most of the pairs aren't even close to each other ...
  3. [3]
    (PDF) Efficient Large-Scale Sweep and Prune Methods with AABB ...
    Collision detection is often split into two phases: a broad-phase, which formulates a potential collision list for each particle (neighbor list), and a narrow- ...
  4. [4]
    [PDF] Interactive and Exact Collision Detection for Multi-Body ... - GAMMA
    This paper focuses on collision detection for ... tation details of the Sweep and Prune algorithm, the exact collision detection algorithm, ... First ...
  5. [5]
    [PDF] An Interactive and Exact Collision Detection System for Large-Scale ...
    We present an exact and interactive collision detection system, I-COLLIDE, for large-scale environments. Such environments are characterized by the number ...
  6. [6]
    [PDF] Collision Detection: Algorithms and Applications - GAMMA
    The I COLLIDE routines are able to compute all contacts between environments composed of hun- dred of convex polytopes at interactive rates (about. 1=20 of a ...
  7. [7]
    [PDF] Rigid Body Simulation II—Nonpenetration Constraints
    The problem can be solved initially by a sort and sweep algorithm. A sorted list of all the bi and ei values is created, from lowest to highest. The list is ...
  8. [8]
    [PDF] Efficient Large-Scale Sweep and Prune Methods with AABB ...
    An improved variant of the broad phase collision-detection algorithm called Sweep and Prune (SaP) for large datasets in three-dimensional environments that ...
  9. [9]
    [PDF] Sweep-and-prune I) Single SAP - CODER CORNER
    The sweep-and-prune (SAP) [8] is a broad-phase algorithm whose goal is to determine overlapping pairs of objects in a 3D world. An object in the SAP is defined ...
  10. [10]
    Chapter 32. Broad-Phase Collision Detection with CUDA
    1 Sort and Sweep. One approach to the broad phase, as mentioned, is the sort and sweep algorithm (Witkin and Baraff 1997). In this approach, the bounding ...
  11. [11]
    [PDF] Collision Detection Crash Course - GDC Vault
    collision detection is something for the not-so-near future. » In game ... Re-order endpoints of moving objects. B. A. Page 77. Sweep and Prune (3/3).
  12. [12]
    [PDF] Dynamic Adaptation of Broad Phase Collision Detection Algorithms
    Jan 14, 2011 · In I-COLLIDE [5] used ”Sweep and Prune”, a pseudo-dynamic object collision pruning method that reduced 3D collision detection between AABBs ...
  13. [13]
    [PDF] Rigid Body Simulation II—Nonpenetration Constraints
    Please note: This document is 1997 by David Baraff. This chapter may be ... Analytical methods for dynamic simulation of non-penetrating rigid bodies.<|control11|><|separator|>
  14. [14]
    [PDF] Adaptive Collision Culling for Large-Scale Simulations by a Parallel ...
    We propose a parallel Sweep and Prune algorithm that solves the dynamic box intersection problem in three di- mensions. It scales up to very large datasets, ...<|control11|><|separator|>
  15. [15]
    Adaptive Collision Culling for Massive Simulations by a Parallel and ...
    Abstract—We present an improved parallel Sweep and Prune algorithm that solves the dynamic box intersection problem in three dimensions.
  16. [16]
    [PDF] Parallel Continuous Collision Detection for High-Performance GPU ...
    Hence, we can use a continuous bounding volume (CBV) to bound the trajectory of the SBV during the time interval. 3.3 GPU-based Parallel Sweep and Prune. The ...
  17. [17]
    [PDF] Broadphase Collision Detection on the Cell Processor
    Sep 13, 2010 · The sweep and prune algorithm is suited to generally static scenes, where only a small number of objects are moving. It does this by maintaining ...
  18. [18]
    [PDF] Collision Detection: Broad Phase Adaptation from Multi-Core ... - HAL
    We focus on the first step (Broad-phase) and propose three new ways of parallelization of the well-known Sweep and Prune algorithm. We first developed a ...
  19. [19]
    Bullet Collision Detection & Physics Library: btAxisSweep3 Class ...
    The btAxisSweep3 is an efficient implementation of the 3d axis sweep and prune broadphase. It uses arrays rather then lists for storage of the 3 axis.
  20. [20]
    [PDF] Collision detection between geometric models: a survey - GAMMA
    It uses dynamically sized AABBs, linear sweep and prune, and geometric coher- ence to quickly reject the object pairs, that are unlikely to collide within the ...Missing: limitations | Show results with:limitations
  21. [21]
    [PDF] Collision Detection and Proximity Queries SIGGRAPH 2004 Course
    The sweep and prune algorithm used to reduce the number of object pairs that need to undergo further testing will also be discussed. Instead of determining ...
  22. [22]
    [PDF] Chapter 3 Collision Detection
    not used for collision detection. One adaptation of coordinate sorting that has proved quite popular is the sweep and prune method used in I-COLLIDE [28].