Skip to content

Narrow Phase: Direct SAP Narrow Phase

DirectSAPNarrowPhase is a narrow phase component, which is used in the detection phase of a CollisionPipeline. The algorithm is based on the "Sweep and Prune" algorithm, noted SAP.

The Algorithm

As mentioned in Narrow Phase, DirectSAPNarrowPhase input is a list of pairs of collision models. Among this list, if it is the first time that a collision model is provided to DirectSAPNarrowPhase, a list of Axis-Aligned Bounding Box (AABB) is created. Each associated to a collision element of the new collision model. This list is saved from a time step to the next.

In the second step, all the AABB are updated according to the geometry of the collision elements in the current time step. The size of the AABB takes into account the alarm distance defined in the intersection method.

Then, the boxes end points are sorted, according to their position projected on the axis of the greatest variance.

Finally, the sorted end points are processed. A list of active end points is used. If an end point corresponds to the beginning of an AABB, it is added to the active list. If an end point corresponds to the end of an AABB, it is removed from the active list. For each end point, it is tested against the active list.

Direct vs Inc.

DirectSAPNarrowPhase corresponds to the implementation of SAP in its "direct" version, i.e. at each step it sorts all the primitives along an axis (not checking the moving ones) and computes overlapping pairs without saving it. But the memory used to save these primitives is created just once, the first time CollisionModels are added.

Example of Usage

This component is used as follows in XML format:

xml <FreeMotionAnimationLoop /> <DefaultPipeline depth="15" verbose="0" draw="0" /> <BruteForceBroadPhase name="N2" /> <DirectSAPNarrowPhase/> <MinProximityIntersection name="Proximity" alarmDistance="1.5" contactDistance="1" /> <DefaultContactManager name="Response" response="FrictionContactConstraint" />

Narrow phase of the collision detection using sweep and prune.

Target: Sofa.Component.Collision.Detection.Algorithm

namespace: sofa::component::collision::detection::algorithm

parents:

  • NarrowPhaseDetection

Data

Name Description Default value
name object name unnamed
printLog if true, emits extra messages at runtime. 0
tags list of the subsets the objet belongs to
bbox this object bounding box
componentState The state of the component among (Dirty, Valid, Undefined, Loading, Invalid). Undefined
listening if true, handle the events, otherwise ignore the events 0
nbPairs number of pairs of elements sent to narrow phase 0
Visualization
showOnlyInvestigatedBoxes Show only boxes which will be sent to narrow phase 1
Name Description Destination type name
context Graph Node containing this object (or BaseContext::getDefault() if no graph is used) BaseContext
slaves Sub-objects used internally by this object BaseObject
master nullptr for regular objects, or master object for which this object is one sub-objects BaseObject