proximity
¶
Proximity
¶
Bases: MojoBaseModel
Provide high-precision triangle-level distance queries.
-
Code Reference
mujoco_mojoruntime
volume_1
instance-attribute
¶
First volume to perform proximity calculations for.
volume_2
instance-attribute
¶
Second volume 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 volumes 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
¶
Calculates the shortest distance between two volumes 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 ( |
Raises:
| Type | Description |
|---|---|
TypeError
|
If either volume is a |
Source code in src/mujoco_mojo/utils/proximity.py
get_vertex_to_face_proximity
¶
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 | |
|---|---|
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 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | |
get_face_to_face_proximity
¶
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
¶
Calculates the shortest distance between two volumes 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 volume_1, world location of minimum distance on volume_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"],
MetadataLike | None,
] = ["dist", "prox_type"],
) -> None
Registers specific channels for logging.
| Channel | Description | Type |
|---|---|---|
dist |
minimum distance between the volume pair, per the proximity algorithm | scalar |
fromto |
world coordinates of the nearest point on each volume | 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"{volume_1.name}_to_{volume_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 volume in the pair, undersubgroups=(pair_name, "fromto", volume_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'], MetadataLike | 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 | |
|---|---|
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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | |