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 Box

From Leeroopedia
Revision as of 12:45, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Google_deepmind_Mujoco_Engine_Collision_Box.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Physics Simulation, Collision Detection
Last Updated 2026-02-15 04:00 GMT

Overview

Implements box-specific collision detection routines for sphere-box, capsule-box, and box-box geometry pairs in MuJoCo.

Description

This module provides specialized narrow-phase collision functions for pairs involving box geometries. It includes mjraw_SphereBox and mjraw_CapsuleBox for raw (untransformed) collision tests, and their public wrappers mjc_SphereBox and mjc_CapsuleBox that extract geometry info from the model. The mjc_BoxBox function handles the complex case of box-box intersection using the separating axis theorem (SAT) approach. Internal helpers such as mju_clampVec provide utility for clamping vectors to box extents.

Usage

These functions are invoked internally by the collision driver (engine_collision_driver.c) when the broadphase determines that two geometries involving at least one box are close enough to warrant narrow-phase testing. They populate mjContact structures with contact position, depth, and frame information.

Code Reference

Source Location

Key Functions

// Raw sphere-box collision test (no model lookup)
int mjraw_SphereBox(mjContact* con, mjtNum margin,
                    const mjtNum* pos1, const mjtNum* mat1, const mjtNum* size1,
                    const mjtNum* pos2, const mjtNum* mat2, const mjtNum* size2);

// Sphere-box collision (public API, extracts geom info from model)
int mjc_SphereBox(const mjModel* m, const mjData* d, mjContact* con,
                  int g1, int g2, mjtNum margin);

// Raw capsule-box collision test
int mjraw_CapsuleBox(mjContact* con, mjtNum margin,
                     const mjtNum* pos1, const mjtNum* mat1, const mjtNum* size1,
                     const mjtNum* pos2, const mjtNum* mat2, const mjtNum* size2);

// Capsule-box collision (public API)
int mjc_CapsuleBox(const mjModel* m, const mjData* d, mjContact* con,
                   int g1, int g2, mjtNum margin);

// Box-box collision
int mjc_BoxBox(const mjModel* M, const mjData* D, mjContact* con,
               int g1, int g2, mjtNum margin);

Import

#include "engine/engine_collision_primitive.h"

I/O Contract

Inputs

Name Type Required Description
m const mjModel* Yes Physics model containing geometry definitions
d const mjData* Yes Simulation state with current geometry positions and orientations
g1 int Yes Index of first geometry (sphere/capsule/box)
g2 int Yes Index of second geometry (box)
margin mjtNum Yes Contact margin for early-out distance filtering

Outputs

Name Type Description
con mjContact* Array of contact structures populated with position, distance, and contact frame
return value int Number of contacts generated (0 if no contact)

Related Pages

Page Connections

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