Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Mujoco MJWarp Collision GJK

From Leeroopedia
Knowledge Sources
Domains Physics_Simulation, GPU_Computing, NVIDIA_Warp
Last Updated 2026-02-15 04:00 GMT

Overview

MJWarp Collision GJK implements the Gilbert-Johnson-Keerthi distance algorithm, Expanding Polytope Algorithm, and Continuous Collision Detection for convex geometry on the GPU.

Description

This is the core convex collision detection module implementing GJK for distance computation between convex shapes, EPA for penetration depth calculation, and CCD for continuous collision detection. It defines Warp structs for GJKResult, Polytope, and SupportPoint, and provides support function evaluation for all MuJoCo geometry types. The module also implements the multicontact algorithm for generating multiple contact points from face-face and edge-face interactions using polygon clipping.

Usage

Used by the convex narrowphase module when geometry pairs require GJK-based distance computation or CCD. The gjk, ccd, multicontact, and support functions are the primary interfaces called from collision_convex.

Code Reference

Source Location

Key Functions

# Warp structs
@wp.struct
class GJKResult:
    dist: float; x1: wp.vec3; x2: wp.vec3; dim: int; ...

@wp.struct
class Polytope:
    status: int; vert: wp.array; face: wp.array; ...

@wp.struct
class SupportPoint:
    ...

# Core algorithms
def gjk(...)             # GJK distance algorithm
def ccd(...)             # Continuous collision detection
def multicontact(...)    # Multi-contact point generation via polygon clipping
def support(geom, geomtype, dir) -> SupportPoint  # Support function

# EPA (Expanding Polytope Algorithm)
def _epa(...)            # EPA penetration depth
def _epa_witness(...)    # EPA witness points

# Simplex sub-distance routines
def _S1D(s1, s2) -> wp.vec2
def _S2D(s1, s2, s3) -> wp.vec3
def _S3D(s1, s2, s3, s4) -> wp.vec4

Import

from mujoco.mjx.third_party.mujoco_warp._src.collision_gjk import gjk
from mujoco.mjx.third_party.mujoco_warp._src.collision_gjk import ccd
from mujoco.mjx.third_party.mujoco_warp._src.collision_gjk import multicontact
from mujoco.mjx.third_party.mujoco_warp._src.collision_gjk import support

I/O Contract

Inputs

Name Type Required Description
geom1 Geom Yes First convex geometry with position, rotation, size, and mesh data
geom2 Geom Yes Second convex geometry
geomtype1 int Yes GeomType enum for first geometry
geomtype2 int Yes GeomType enum for second geometry

Outputs

Name Type Description
GJKResult struct Distance, witness points (x1, x2), simplex dimension and vertices
contacts array Contact positions, normals, and penetration depths from multicontact

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment