Contenido principal

Collision Mesh

Create convex mesh collision geometry

Since R2025a

  • Collision Mesh block

Libraries:
Robotics System Toolbox / Collision Detection

Description

The Collision Mesh block outputs a convex mesh collision geometry using a list of 3-D vertices relative to a pose specified in relation to the world frame.

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")
### Building simulation target for model: 'CollisionCheckingBetweenGeometries'.
/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/bin/mex -R2018a -c -DMATLAB_MEX_FILE -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/simulink/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/rtw/c/src" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cprj"  -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cgxe/CollisionCheckingBetweenGeometries/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics/collfcncodegen" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src/ccd"  CFLAGS="\$CFLAGS -w   -Dccd_EXPORTS" CollisionCheckingBetweenGeometries_cgxe.c
Building with 'gcc'.
MEX completed successfully.
/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/bin/mex -R2018a -c -DMATLAB_MEX_FILE -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/simulink/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/rtw/c/src" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cprj"  -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cgxe/CollisionCheckingBetweenGeometries/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics/collfcncodegen" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src/ccd"  CFLAGS="\$CFLAGS -w   -Dccd_EXPORTS" CollisionCheckingBetweenGeometries_cgxe_registry.c
Building with 'gcc'.
MEX completed successfully.
/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/bin/mex -R2018a -c -DMATLAB_MEX_FILE -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/simulink/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/rtw/c/src" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cprj"  -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cgxe/CollisionCheckingBetweenGeometries/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics/collfcncodegen" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src/ccd"  CFLAGS="\$CFLAGS -w   -Dccd_EXPORTS" m_GhFrblLuZIHYWtKepSDIND.c
Building with 'gcc'.
MEX completed successfully.
/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/bin/mex -R2018a -c -DMATLAB_MEX_FILE -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/simulink/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/rtw/c/src" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cprj"  -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cgxe/CollisionCheckingBetweenGeometries/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics/collfcncodegen" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src/ccd"  CFLAGS="\$CFLAGS -w   -Dccd_EXPORTS" m_4heBl51EEsIlbER46Li5jD.c
Building with 'gcc'.
MEX completed successfully.
/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/bin/mex -R2018a -c -DMATLAB_MEX_FILE -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/simulink/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/rtw/c/src" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cprj"  -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cgxe/CollisionCheckingBetweenGeometries/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics/collfcncodegen" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src/ccd"  CFLAGS="\$CFLAGS -w   -Dccd_EXPORTS" m_nO7LkfNziknjFjiV4wtacG.c
Building with 'gcc'.
MEX completed successfully.
/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/bin/mex -R2018a -c -DMATLAB_MEX_FILE -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/simulink/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/rtw/c/src" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cprj"  -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cgxe/CollisionCheckingBetweenGeometries/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics/collfcncodegen" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src/ccd"  CFLAGS="\$CFLAGS -w   -Dccd_EXPORTS" m_pUaOgr0KJnPvwlP7Ju7YCG.c
Building with 'gcc'.
MEX completed successfully.
/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/bin/mex -R2018a -c -DMATLAB_MEX_FILE -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/simulink/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/rtw/c/src" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cprj"  -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cgxe/CollisionCheckingBetweenGeometries/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics/collfcncodegen" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src/ccd"  CFLAGS="\$CFLAGS -w   -Dccd_EXPORTS" m_mqsM2RT6XtQ2LVLHaaUPnC.c
Building with 'gcc'.
MEX completed successfully.
/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/bin/mex -R2018a -c -DMATLAB_MEX_FILE -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/simulink/include" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/rtw/c/src" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870" -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cprj"  -I"/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cgxe/CollisionCheckingBetweenGeometries/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/extern/include/shared_robotics/collfcncodegen" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src" -I"/mathworks/devel/bat/filer/batfs2566-0/Bdoc26a.3228664.Bdoc26a.3222347.noreset/build/runnable/matlab/toolbox/shared/robotics/externalDependency/libccd/src/ccd"  CFLAGS="\$CFLAGS -w   -Dccd_EXPORTS" m_sizVKYDMGZetO85ZcDubrF.c
Building with 'gcc'.
/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cgxe/CollisionCheckingBetweenGeometries/src/m_sizVKYDMGZetO85ZcDubrF.c: In function ‘CollisionGeometryBuildableFunctional_intersect’:
/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cgxe/CollisionCheckingBetweenGeometries/src/m_sizVKYDMGZetO85ZcDubrF.c:514:22: error: passing argument 16 of ‘fromMLToCollStruct’ from incompatible pointer type [-Wincompatible-pointer-types]
  514 |                      &geom1struct.m_Vertices, &geom1struct.m_NumVertices,
      |                      ^~~~~~~~~~~~~~~~~~~~~~~
      |                      |
      |                      const real64_T ** {aka const double **}
/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cgxe/CollisionCheckingBetweenGeometries/src/m_sizVKYDMGZetO85ZcDubrF.c:114:43: note: expected ‘real64_T **’ {aka ‘double **’} but argument is of type ‘const real64_T **’ {aka ‘const double **’}
  114 |   real_T *geomstruct_m_Height, real64_T* *geomstruct_m_Vertices, uint32_T
      |                                ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cgxe/CollisionCheckingBetweenGeometries/src/m_sizVKYDMGZetO85ZcDubrF.c:521:22: error: passing argument 16 of ‘fromMLToCollStruct’ from incompatible pointer type [-Wincompatible-pointer-types]
  521 |                      &geom2struct.m_Vertices, &geom2struct.m_NumVertices,
      |                      ^~~~~~~~~~~~~~~~~~~~~~~
      |                      |
      |                      const real64_T ** {aka const double **}
/tmp/Bdoc26a_3228664_92953/tp753e75de/robotics-ex29391870/slprj/_cgxe/CollisionCheckingBetweenGeometries/src/m_sizVKYDMGZetO85ZcDubrF.c:114:43: note: expected ‘real64_T **’ {aka ‘double **’} but argument is of type ‘const real64_T **’ {aka ‘const double **’}
  114 |   real_T *geomstruct_m_Height, real64_T* *geomstruct_m_Vertices, uint32_T
      |                                ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~

gmake: *** [m_sizVKYDMGZetO85ZcDubrF.o] Error 255



### Build procedure for model: 'CollisionCheckingBetweenGeometries' aborted due to an error.

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;

Ports

Input

expand all

Vertices of the mesh, specified as an N-by-3 matrix, where N is the number of vertices and must greater than or equal to 1. Each row of Vertices represents the coordinates of a point in 3-D space. Note that some of the points can be inside the constructed convex mesh.

Pose of the collision geometry relative to the world frame, specified as a 4-by-4 homogeneous matrix.

Output

expand all

Collision geometry, returned as a bus.

To perform collision checking, connect this output to a Check Collision block as input.

Validity of collision mesh vertices, returned as one of these values:

  • 4 — Vertices matrix contains values nonnumeric.

  • 3 — Vertices matrix contains values that are not real.

  • 2 — Vertices matrix contains nonfinite values.

  • 1 — Vertices matrix does not have three columns.

  • 0 — Vertices are valid.

To validate vertices at runtime instead, select the Enable Runtime Input Dimensions Error parameter.

Data Types: uint16

Parameters

expand all

To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.

Select this parameter to enable runtime validation of the collision mesh vertices and return an error if Vertices is invalid.

If you clear this parameter, the block does not error during simulation, and instead uses the ExitFlag port to identify invalid mesh vertices.

  • Code generation — Simulate model using generated C code. The first time you run a simulation, Simulink generates C code for the block. The block reuses the C code for subsequent simulations, as long as the model does not change.

  • Interpreted execution — Simulate model using the MATLAB® interpreter. For more information, see Interpreted Execution vs. Code Generation (Simulink).

More About

expand all

Extended Capabilities

expand all

Version History

Introduced in R2025a