Implementation:Google deepmind Mujoco Engine Collision Primitive
| Knowledge Sources | |
|---|---|
| Domains | Physics Simulation, Collision Detection |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Implements closed-form collision detection for primitive geometry pairs: planes, spheres, capsules, cylinders, and boxes.
Description
This module provides efficient, analytic narrow-phase collision routines for the simplest geometry pair combinations that do not require iterative convex algorithms. It covers plane collisions with spheres, capsules, cylinders, and boxes, as well as sphere-sphere, sphere-capsule, sphere-cylinder, and capsule-capsule pairs. It also provides raw (untransformed) collision functions for sphere-triangle, box-triangle, and capsule-triangle tests used by heightfield and mesh collision routines. Each function computes contact positions, penetration depths, and contact frames.
Usage
These functions are registered in the mjCOLLISIONFUNC dispatch table in engine_collision_driver.c and are invoked for primitive geometry pairs during narrow-phase collision detection.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/engine/engine_collision_primitive.c
- Lines: 1-766
Key Functions
// Plane collisions
int mjc_PlaneSphere(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, mjtNum margin);
int mjc_PlaneCapsule(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, mjtNum margin);
int mjc_PlaneCylinder(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, mjtNum margin);
int mjc_PlaneBox(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, mjtNum margin);
// Sphere collisions
int mjc_SphereSphere(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, mjtNum margin);
int mjc_SphereCapsule(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, mjtNum margin);
int mjc_SphereCylinder(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, mjtNum margin);
// Capsule collisions
int mjc_CapsuleCapsule(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, mjtNum margin);
// Raw triangle collision functions (used by heightfield/mesh routines)
int mjraw_SphereTriangle(mjContact* con, mjtNum margin, ...);
int mjraw_BoxTriangle(mjContact* con, mjtNum margin, const mjtNum* pos, ...);
int mjraw_CapsuleTriangle(mjContact* con, mjtNum margin, const mjtNum* pos, ...);
Import
#include "engine/engine_collision_primitive.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| m | const mjModel* | Yes | Physics model with geometry definitions |
| d | const mjData* | Yes | Simulation state with geometry transforms |
| g1 | int | Yes | Index of first geometry |
| g2 | int | Yes | Index of second geometry |
| margin | mjtNum | Yes | Contact margin for distance filtering |
Outputs
| Name | Type | Description |
|---|---|---|
| con | mjContact* | Contact array populated with position, depth, and frame |
| return value | int | Number of contacts generated (0 if none) |