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 Engine Collision Convex

From Leeroopedia
Knowledge Sources
Domains Physics Simulation, Collision Detection, Computational Geometry
Last Updated 2026-02-15 04:00 GMT

Overview

Implements general-purpose convex collision detection using support functions, CCD (Continuous Collision Detection), and the MPR/EPA algorithms for arbitrary convex geometry pairs.

Description

This module is the primary entry point for convex-convex collision detection in MuJoCo. It defines support functions for each geometry type (sphere, capsule, ellipsoid, cylinder, box, mesh, flex) which compute the farthest point on a geometry in a given direction. These support functions are used by both the libccd library (via mjccd_support, mjccd_center) and MuJoCo's native GJK/EPA implementation. The module also handles heightfield collisions (mjc_ConvexHField), plane-convex collisions (mjc_PlaneConvex), contact normal fixing (mjc_fixNormal), and CCD object initialization (mjc_initCCDObj).

Usage

Called by the collision driver when pairs of convex geometries (ellipsoids, cylinders, meshes, etc.) require narrow-phase testing. The main entry point mjc_Convex orchestrates CCD-based collision iteration and can produce multiple contacts for conforming geometry pairs.

Code Reference

Source Location

Key Functions

// CCD center function for convex collision algorithms
void mjc_center(mjtNum res[3], const mjCCDObj* obj);
void mjccd_center(const void* obj, ccd_vec3_t* center);

// Support functions for various geometry types
void mjc_pointSupport(mjtNum res[3], mjCCDObj* obj, const mjtNum dir[3]);
void mjc_lineSupport(mjtNum res[3], mjCCDObj* obj, const mjtNum dir[3]);
void mjccd_support(const void* _obj, const ccd_vec3_t* _dir, ccd_vec3_t* vec);

// Initialize CCD object from model geometry
void mjc_initCCDObj(mjCCDObj* obj, const mjModel* m, const mjData* d,
                    int g, mjtNum margin);

// General convex-convex collision
int mjc_Convex(const mjModel* m, const mjData* d,
               mjContact* con, int g1, int g2, mjtNum margin);

// Plane-convex collision
int mjc_PlaneConvex(const mjModel* m, const mjData* d,
                    mjContact* con, int g1, int g2, mjtNum margin);

// Convex-heightfield collision
int mjc_ConvexHField(const mjModel* m, const mjData* d,
                     mjContact* con, int g1, int g2, mjtNum margin);

// Fix contact normal for mesh/ellipsoid geometries
void mjc_fixNormal(const mjModel* m, const mjData* d,
                   mjContact* con, int g1, int g2);

Import

#include "engine/engine_collision_convex.h"

I/O Contract

Inputs

Name Type Required Description
m const mjModel* Yes Physics model with geometry and mesh data
d const mjData* Yes Simulation state with current poses
g1 int Yes Index of first geometry
g2 int Yes Index of second geometry
margin mjtNum Yes Contact margin distance

Outputs

Name Type Description
con mjContact* Populated contact array with positions, normals, and penetration depths
return value int Number of contacts detected

Related Pages

Page Connections

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