newton.geometry.BroadPhaseSAP#
- class newton.geometry.BroadPhaseSAP(max_broad_phase_elements, max_num_distinct_positive_groups, max_num_negative_group_members, sweep_thread_count_multiplier=5)[source]#
Bases:
object
Sweep and Prune (SAP) broad phase collision detection.
This class implements the sweep and prune algorithm for broad phase collision detection. It efficiently finds potentially colliding pairs of objects by sorting their bounding box projections along a fixed axis and checking for overlaps.
- __init__(max_broad_phase_elements, max_num_distinct_positive_groups, max_num_negative_group_members, sweep_thread_count_multiplier=5)#
Initialize arrays for sweep and prune broad phase collision detection.
- Parameters:
max_broad_phase_elements (int) – Maximum number of elements to process
max_num_distinct_positive_groups (int) – Maximum number of unique positive collision groups
max_num_negative_group_members (int) – Maximum number of elements with negative groups
sweep_thread_count_multiplier (int) – Multiplier for number of threads used in sweep phase
- launch(geom_lower, geom_upper, geom_cutoffs, geom_collision_groups, geom_count, candidate_pair, num_candidate_pair)#
Launch the sweep and prune broad phase collision detection.
This method performs collision detection between geometries using a sweep and prune algorithm along a fixed axis. It projects the bounding boxes onto the sweep axis, sorts them, and checks for overlaps between nearby boxes. The method also handles collision filtering based on collision groups.
- 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_groups (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_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
The method will populate candidate_pair with the indices of geometry pairs whose AABBs overlap when expanded by their cutoff distances and whose collision groups allow interaction. The number of pairs found will be written to num_candidate_pair[0].