Main Content

Check Collision

Check if two convex collision geometries are in collision

Since R2025a

  • Check Collision block

Libraries:
Robotics System Toolbox / Collision Detection

Description

The Check Collision block checks for collision between two convex collision geometries and additionally outputs the separation distance and corresponding witness points between the collision geometries.

Examples

expand all

Open the Simulink® model. This model contains all five of the collision geometry blocks in the Collision Detection library and checks for collision between any two of the collision geometries. Note that the Collision Mesh block uses vertices from the exampleMeshVertices MAT file. The model loads the exampleMeshVertices MAT file when you open the model by using the PreLoadFcn callback.

model = "CollisionCheckingBetweenGeometries.slx";
open_system(model)

Simulate the model.

out = sim("CollisionCheckingBetweenGeometries.slx")
out = 
  Simulink.SimulationOutput:

             collStatus: [1x1 timeseries] 
               geom1Idx: [1x1 timeseries] 
               geom2Idx: [1x1 timeseries] 
                logsout: [1x1 Simulink.SimulationData.Dataset] 
                sepDist: [1x1 timeseries] 
                   tout: [101x1 double] 
             witnessPts: [1x1 timeseries] 

     SimulationMetadata: [1x1 Simulink.SimulationMetadata] 
           ErrorMessage: [0x0 char] 

Get data from the simulation output.

collCheckingPairs = [out.geom1Idx.Data out.geom2Idx.Data];
collStatuses = out.collStatus.Data;
sepDistances = out.sepDist.Data;
witnessPoints = out.witnessPts.Data;

Limitations

  • Collision checking results are unreliable when the minimal distance is below 10-5 m.

Ports

Input

expand all

First collision geometry, specified as a bus created by any of these collision geometry blocks:

Second collision geometry, specified as a bus created by any of these collision geometry blocks:

Output

expand all

Collision status, returned as a Boolean 0 or 1. If the two geometries are in collision, CollStatus outputs 1. Otherwise, the value is 0.

Minimum distance between the two collision geometries, returned as a scalar. The line segment that connects the witness points WitnessPts, determines the minimum distance between the two geometries. When the two geometries are in collision, SepDist outputs NaN.

Witness points on each geometry, returned as a 3-by-2 matrix. The first column is the location of the witness point on the geometry Geom1, and the second column is the location of the witness point on the other geometry Geom2. The length of the line segment that connects the two witness points determines the value from the SepDist port. When the two geometries are in collision, every element of WitnessPts is NaN.

Extended Capabilities

expand all

Version History

Introduced in R2025a