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 MJX Ray

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

Overview

JAX-based ray intersection testing functions for casting rays against MuJoCo geom primitives including planes, spheres, capsules, ellipsoids, boxes, and meshes.

Description

This module implements analytic ray-geom intersection tests for all supported MuJoCo geometry types. Each primitive has a dedicated function (e.g., _ray_plane, _ray_sphere, _ray_capsule) that computes the distance along a ray to the first intersection point. For quadric surfaces, intersections are found by solving quadratic equations via _ray_quad. The top-level ray() function casts a ray against all geoms in the scene, and ray_geom() tests against a single specified geom. Results return jp.inf when no intersection occurs.

Usage

Used by sensor functions (e.g., rangefinder sensors) during the mjx.step() pipeline to compute ray-based distance measurements. Also available for user-level ray queries against the simulation scene.

Code Reference

Source Location

Key Functions

def _ray_quad(a: jax.Array, b: jax.Array, c: jax.Array) -> Tuple[jax.Array, jax.Array]
def _ray_plane(size: jax.Array, pnt: jax.Array, vec: jax.Array) -> jax.Array
def _ray_sphere(size: jax.Array, pnt: jax.Array, vec: jax.Array) -> jax.Array
def _ray_capsule(size: jax.Array, pnt: jax.Array, vec: jax.Array) -> jax.Array
def _ray_ellipsoid(size: jax.Array, pnt: jax.Array, vec: jax.Array) -> jax.Array
def _ray_box(size: jax.Array, pnt: jax.Array, vec: jax.Array) -> jax.Array
def _ray_triangle(vert: jax.Array, pnt: jax.Array, vec: jax.Array) -> jax.Array
def _ray_mesh(m: Model, d: Data, geom_id: int, pnt: jax.Array, vec: jax.Array) -> jax.Array
def ray(m: Model, d: Data, pnt: jax.Array, vec: jax.Array, ...) -> Tuple[jax.Array, jax.Array]
def ray_geom(m: Model, d: Data, geom_id: int, pnt: jax.Array, vec: jax.Array) -> jax.Array

Import

from mujoco.mjx._src.ray import ray
from mujoco.mjx._src.ray import ray_geom

I/O Contract

Inputs

Name Type Required Description
m mjx.Model Yes JAX model with geom shape data
d mjx.Data Yes JAX simulation data with geom transforms
pnt jax.Array Yes Ray origin point (3,)
vec jax.Array Yes Ray direction vector (3,)
geom_id int No Specific geom to test against (for ray_geom)

Outputs

Name Type Description
dist jax.Array Distance to intersection (jp.inf if no hit)
geom_id jax.Array ID of the nearest intersected geom (for ray())

Related Pages

Page Connections

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