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
¶
get_sphere_to_sphere_proximity(
mj_model: MjModel, mj_data: MjData
) -> tuple[float, Vec3, Vec3, bool]
Calculates the shortest distance between two geometries using their bounding spheres.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mj_model
|
MjModel
|
The compiled MuJoCo model instance. |
required |
mj_data
|
MjData
|
The current simulation state. |
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(
mj_model: MjModel, mj_data: MjData
) -> tuple[float, Vec3, Vec3, ProximityType]
Calculates the shortest distance between two geometries using their convex hull.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mj_model
|
MjModel
|
The compiled MuJoCo model instance. |
required |
mj_data
|
MjData
|
The current simulation state. |
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(
mj_model: MjModel, mj_data: MjData
) -> 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 |
|---|---|---|---|
mj_model
|
MjModel
|
Compiled MuJoCo model. |
required |
mj_data
|
MjData
|
MuJoCo runtime data. |
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 | |
|---|---|
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 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 | |
get_face_to_face_proximity
¶
get_face_to_face_proximity(
mj_model: MjModel, mj_data: MjData
) -> 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 |
|---|---|---|---|
mj_model
|
MjModel
|
Compiled MuJoCo model. |
required |
mj_data
|
MjData
|
MuJoCo runtime data. |
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(
mj_model: MjModel, mj_data: MjData
) -> 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 |
|---|---|---|---|
mj_model
|
MjModel
|
Compiled MuJoCo model. |
required |
mj_data
|
MjData
|
MuJoCo runtime data. |
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. |
Source code in src/mujoco_mojo/utils/proximity.py
request
¶
request(
signal_manager: SignalManager,
attrs: list[Literal["dist", "fromto", "prox_type"]] = [
"dist",
"prox_type",
],
)
Registers specific geom proximity attributes for logging. Please see the get_proximity method for how these outputs are calculated.
Available Requests
dist: Minimum distance as calculated by the specified algorithm. Tagged with Proximities/{pair_name}:dist.
fromto: World coordinates for where the minimum distance is estimated to occur at. Two sets of coordinates will be returned for geom_1 and geom_2. Tagged with Proximities/{pair_name}/fromto/{(geom_1 | geom_2).name}:(x | y | z).
prox_type: What type of proximity calculation the previous values are from. Using dist_max, get_proximity can return a broadphase estimate (bounding sphere to sphere) if the two geometries are distant (greater than dist_max). This telemetry will return what type of proximity calculation was performed for this timestep. It is intended to help debug to understand if a jump in telemetry (specifically sharp declines) are real or comes from the broadphase estimate. The values returned will be integer values associated with their specific ProximityType (see the enumeration for the mapping, in general a larger value will mean a more accurate one). Tagged with Proximities/{pair_name}:prox_type.