Implementation:Google deepmind Mujoco MJWarp Collision Primitive Core
| Knowledge Sources | |
|---|---|
| Domains | Physics_Simulation, GPU_Computing, NVIDIA_Warp |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
MJWarp Collision Primitive Core provides the core analytical collision detection functions for primitive geometry pairs as GPU-compatible Warp functions.
Description
This module contains the low-level mathematical implementations of collision detection between primitive geometry types. It provides Warp functions for computing closest points, penetration depths, and contact normals for all supported primitive pairs. These functions implement the analytical geometry formulas from MuJoCo's C engine, translated to run on the GPU via NVIDIA Warp. Utility functions include closest-point-on-segment, segment-to-segment distance, and safe division operations.
Usage
Called by collision_primitive.py wrapper functions to compute the actual collision geometry. These are pure geometric functions that return contact positions, normals, and depths without handling contact parameter computation or output writing.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: mjx/mujoco/mjx/third_party/mujoco_warp/_src/collision_primitive_core.py
- Lines: 1-1491
Key Functions
# Utility functions
def safe_div(x, y) -> Any
def normalize_with_norm(x) -> (normalized, norm)
def closest_segment_point(a, b, pt) -> wp.vec3
def closest_segment_point_and_dist(a, b, pt) -> Tuple[wp.vec3, float]
def closest_segment_to_segment_points(a0, a1, b0, b1) -> Tuple[wp.vec3, wp.vec3]
# Primitive collision functions
def plane_sphere(plane_normal, plane_pos, sphere_pos, sphere_radius) -> Tuple[float, wp.vec3]
def sphere_sphere(...)
def sphere_capsule(...)
def capsule_capsule(...)
def plane_capsule(...)
def plane_ellipsoid(...)
def plane_box(...)
def plane_cylinder(...)
def sphere_cylinder(...)
def sphere_box(...)
def capsule_box(...)
def box_box(...)
Import
from mujoco.mjx.third_party.mujoco_warp._src.collision_primitive_core import plane_sphere
from mujoco.mjx.third_party.mujoco_warp._src.collision_primitive_core import sphere_sphere
from mujoco.mjx.third_party.mujoco_warp._src.collision_primitive_core import box_box
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| pos1 | wp.vec3 | Yes | Position of first geometry |
| mat1 | wp.mat33 | Yes | Rotation matrix of first geometry |
| size1 | wp.vec3 | Yes | Size parameters of first geometry |
| pos2 | wp.vec3 | Yes | Position of second geometry |
| mat2 | wp.mat33 | Yes | Rotation matrix of second geometry |
| size2 | wp.vec3 | Yes | Size parameters of second geometry |
Outputs
| Name | Type | Description |
|---|---|---|
| dist | float | Signed distance or penetration depth |
| pos | wp.vec3 | Contact point position |
| normal | wp.vec3 | Contact normal direction |