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 Primitive

From Leeroopedia
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

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)

Related Pages

Page Connections

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