Implementation:Google deepmind Mujoco MJX Collision Primitive
| Knowledge Sources | |
|---|---|
| Domains | Physics_Simulation, JAX, Collision_Detection |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Analytical collision functions for primitive geometry pairs (plane, sphere, capsule, ellipsoid, cylinder) using closed-form contact point and distance calculations.
Description
This module implements collision detection between simple geometric primitives where closed-form analytical solutions exist. It covers plane-sphere, plane-capsule, plane-ellipsoid, plane-cylinder, sphere-sphere, sphere-capsule, and capsule-capsule pairs. Each function is wrapped by the collider decorator which handles geom data extraction, vmapping over geom pairs, and multi-contact concatenation. The contact output follows the standard MJX Collision tuple format: (distance, position, frame).
Usage
These functions are registered in the collision function table by collision_driver.py and dispatched for the appropriate geom type pairs during the contact detection phase of mjx.step().
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: mjx/mujoco/mjx/_src/collision_primitive.py
- Lines: 1-208
Key Functions
def collider(ncon: int)
def plane_sphere(plane: GeomInfo, sphere: GeomInfo) -> Collision
def plane_capsule(plane: GeomInfo, cap: GeomInfo) -> Collision
def plane_ellipsoid(plane: GeomInfo, ellipsoid: GeomInfo) -> Collision
def plane_cylinder(plane: GeomInfo, cylinder: GeomInfo) -> Collision
def sphere_sphere(s1: GeomInfo, s2: GeomInfo) -> Collision
def sphere_capsule(sphere: GeomInfo, cap: GeomInfo) -> Collision
def capsule_capsule(cap1: GeomInfo, cap2: GeomInfo) -> Collision
Import
from mujoco.mjx._src.collision_primitive import plane_sphere
from mujoco.mjx._src.collision_primitive import sphere_sphere
from mujoco.mjx._src.collision_primitive import capsule_capsule
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| m | mjx.Model | Yes | JAX model (used in collider wrapper) |
| d | mjx.Data | Yes | JAX simulation data with geom positions/orientations |
| plane / sphere / cap / ellipsoid / cylinder | GeomInfo | Yes | Geom properties: position, rotation matrix, and size |
| geom | jax.Array | Yes | Array of geom index pairs |
Outputs
| Name | Type | Description |
|---|---|---|
| dist | jax.Array | Penetration distance (negative means overlap) |
| pos | jax.Array | Contact point position |
| frame | jax.Array | Contact frame (3x3); normal in row 0 |