Check Collision

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
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;
Limitations
Collision checking results are unreliable when the minimal distance is below 10-5 m.
Ports
Input
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
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.
Parameters
To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.
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).
Extended Capabilities
The Check Collision block supports code generation with dynamic memory allocation disabled. For more information about disabling dynamic memory allocation, see Dynamic memory allocation in MATLAB functions (Simulink).
Version History
Introduced in R2025a
See Also
Functions
Blocks
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)