newton.geometry.BroadPhaseAllPairs#
- class newton.geometry.BroadPhaseAllPairs(geom_world, geom_flags=None, device=None)[source]#
Bases:
objectA broad phase collision detection class that performs N x N collision checks between all geometry pairs.
This class performs collision detection between all possible pairs of geometries by checking for axis-aligned bounding box (AABB) overlaps. It uses a lower triangular matrix approach to avoid checking each pair twice.
The collision checks take into account per-geometry cutoff distances and collision groups. Two geometries will only be considered as a candidate pair if: 1. Their AABBs overlap when expanded by their cutoff distances 2. Their collision groups allow interaction (determined by test_group_pair())
The class outputs an array of candidate collision pairs that need more detailed narrow phase collision checking.
- __init__(geom_world, geom_flags=None, device=None)#
Initialize the broad phase with world ID information.
- Parameters:
geom_world – Array of world IDs (numpy or warp array). Positive/zero values represent distinct worlds, negative values represent shared entities that belong to all worlds.
geom_flags – Optional array of shape flags (numpy or warp array). If provided, only shapes with the COLLIDE_SHAPES flag will be included in collision checks. This efficiently filters out visual-only shapes.
device – Device to store the precomputed arrays on. If None, uses CPU for numpy arrays or the device of the input warp array.
- launch(geom_lower, geom_upper, geom_cutoffs, geom_collision_group, geom_shape_world, geom_count, candidate_pair, num_candidate_pair, device=None)#
Launch the N x N broad phase collision detection.
This method performs collision detection between all possible pairs of geometries by checking for axis-aligned bounding box (AABB) overlaps. It uses a lower triangular matrix approach to avoid checking each pair twice.
- Parameters:
geom_lower (array(ndim=1, dtype=vec3f)) – Array of lower bounds for each geometry’s AABB
geom_upper (array(ndim=1, dtype=vec3f)) – Array of upper bounds for each geometry’s AABB
geom_cutoffs (array(ndim=1, dtype=float32)) – Array of cutoff distances for each geometry
geom_collision_group (array(ndim=1, dtype=int32)) – Array of collision group IDs for each geometry. Positive values indicate groups that only collide with themselves (and with negative groups). Negative values indicate groups that collide with everything except their negative counterpart. Zero indicates no collisions.
geom_shape_world (array(ndim=1, dtype=int32)) – Array of world indices for each geometry. Index -1 indicates global entities that collide with all worlds. Indices 0, 1, 2, … indicate world-specific entities.
geom_count (int) – Number of active bounding boxes to check
candidate_pair (array(ndim=1, dtype=vec2i)) – Output array to store overlapping geometry pairs
num_candidate_pair (array(ndim=1, dtype=int32)) – Output array to store number of overlapping pairs found
device – Device to launch on. If None, uses the device of the input arrays.
The method will populate candidate_pair with the indices of geometry pairs (i,j) where i < j whose AABBs overlap when expanded by their cutoff distances, whose collision groups allow interaction, and whose world indices are compatible (same world or at least one is global). The number of pairs found will be written to num_candidate_pair[0].