Proximity
proximity
¶
Proximity
¶
Bases: MojoBaseModel
Provide high-precision triangle-level distance queries.
geom_1
instance-attribute
¶
First geometry to perform proximity calculations for.
geom_2
instance-attribute
¶
Second geometry to perform proximity calculations for.
dist_max
instance-attribute
¶
dist_max: float
The 'cutoff' distance. If objects are further than this (as estimated by a sphere to sphere test), the sphere to sphere estimate will be returned and exit early.
algorithm
class-attribute
instance-attribute
¶
algorithm: ProximityType = CONVEX_HULL
What algorithm should be used for the narrowphase test.
visualize
class-attribute
instance-attribute
¶
visualize: bool = True
Wheter or not to visualize this proximity in the MuJoCo viewer.
get_sphere_to_sphere_proximity
¶
Calculates the shortest distance between two geometries using their bounding spheres.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
MjState
|
The paired MuJoCo model and data instance. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, Vec3, Vec3, bool]
|
tuple[float, Vec3, Vec3, bool]: Unsigned ( |
Source code in src/mujoco_mojo/utils/proximity.py
get_convex_hull_proximity
¶
get_convex_hull_proximity(
state: MjState,
) -> tuple[float, Vec3, Vec3, ProximityType]
Calculates the shortest distance between two geometries using their convex hull.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
MjState
|
The paired MuJoCo model and data instance. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, Vec3, Vec3, ProximityType]
|
tuple[float, Vec3, Vec3, ProximityType]: Unsigned ( |
Source code in src/mujoco_mojo/utils/proximity.py
get_vertex_to_face_proximity
¶
get_vertex_to_face_proximity(
state: MjState,
) -> tuple[float, Vec3, Vec3, ProximityType]
Calculates the vertex to face distance using a multi-phase Bounding Volume Hierarchy (BVH) query.
Phases
- Broad Phase: Sphere-Sphere check (object level).
- Mid Phase: BVH Traversal (eliminating triangle groups). No exit here.
- Narrow Phase: Point-to-Face proximity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
MjState
|
The paired MuJoCo model and data instance. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, Vec3, Vec3, ProximityType]
|
tuple[float, Vec3, Vec3, ProximityType]: Unsigned ( |
Source code in src/mujoco_mojo/utils/proximity.py
| Python | |
|---|---|
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
get_face_to_face_proximity
¶
get_face_to_face_proximity(
state: MjState,
) -> tuple[float, Vec3, Vec3, ProximityType]
Calculates the face to face distance using a multi-phase Bounding Volume Hierarchy (BVH) query.
This is more accurate than the vertex to face method, but comes at higher computational cost.
Phases
- Broad Phase: Sphere-Sphere check (object level).
- Mid Phase: BVH Traversal (eliminating triangle groups). No exit here.
- Narrow Phase: Face-to-Face proximity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
MjState
|
The paired MuJoCo model and data instance. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, Vec3, Vec3, ProximityType]
|
tuple[float, Vec3, Vec3, ProximityType]: Unsigned ( |
Source code in src/mujoco_mojo/utils/proximity.py
get_proximity
¶
get_proximity(
state: MjState,
) -> tuple[float, Vec3, Vec3, ProximityType]
Calculates the shortest distance between two geometries using the specified proximity algorithm.
This is a general dispatcher method that routes to different proximity calculation algorithms based on the algorithm parameter. Each mode offers different tradeoffs between speed and precision:
Modes:
- SPHERE_TO_SPHERE: Fastest. Uses bounding sphere distance only (broadphase).
- CONVEX_HULL: Fast & accurate. Uses MuJoCo's convex hull-based distance (default).
- VERTEX_TO_FACE: Accurate. Multi-phase BVH with vertex-to-surface queries.
- FACE_TO_FACE: Most accurate but slowest. Full mesh-to-mesh distance calculation.
Phases (for non-sphere modes): 1. Broad Phase: Sphere-Sphere check (object level). 2. Narrow Phase: Algorithm-specific distance calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
MjState
|
The paired MuJoCo model and data instance. |
required |
Returns:
| Type | Description |
|---|---|
float
|
tuple[float, ProximityType]: If fromto=False, returns the unsigned ( |
Vec3
|
tuple[tuple[float, Vec3, Vec3], ProximityType]: If fromto=True, returns the minimum distance, world location of minimum distance on geom_1, world location of minimum distance on geom_2, and which algorithm produced the result. |
The result is cached per-timestep (keyed on state.data.time), so calling this more than once during the same step (e.g. once from request()'s telemetry sampler and again from a user-defined runtime input/Load that reads the same Proximity instance) only pays for the underlying calculation once.
Source code in src/mujoco_mojo/utils/proximity.py
request
¶
request(
signal_manager: SignalManager | None = None,
channels: list[Literal["dist", "fromto", "prox_type"]]
| dict[
Literal["dist", "fromto", "prox_type"],
dict[str, Any] | None,
] = ["dist", "prox_type"],
)
Registers specific channels for logging.
| Channel | Description | Type |
|---|---|---|
dist |
minimum distance between the geom pair, per the proximity algorithm | scalar |
fromto |
world coordinates of the nearest point on each geom | xyz |
prox_type |
the ProximityType used to compute dist and fromto, as an integer |
scalar |
Each channel is posted under subgroups=(pair_name,), where pair_name is f"{geom_1.name}_to_{geom_2.name}".
- A
scalaris posted as a single value withattr=channel. - An
xyzis a cartesian vector without a magnitude component, posted as 3 values (x,y,z).fromtoposts onexyzfor each geom in the pair, undersubgroups=(pair_name, "fromto", geom_name).
Only the computations required by the requested channels are performed each timestep.
Each signal is tagged with built-in dimension/unit metadata for its channel (dist/fromto as a length, prox_type as dimensionless).
If signal_manager is omitted, the SignalManager of the active RuntimeManager with block is used. If that RuntimeManager has no SignalManager configured, this is a no-op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_manager
|
SignalManager | None
|
The signal manager to register the sampler with. |
None
|
channels
|
list[Literal['dist', 'fromto', 'prox_type']] | dict[Literal['dist', 'fromto', 'prox_type'], dict[str, Any] | None]
|
The proximity data channels to log. Pass a list to select channels, or a dict mapping channel name to metadata overrides (or |
['dist', 'prox_type']
|
Source code in src/mujoco_mojo/utils/proximity.py
| Python | |
|---|---|
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |