Skip to content

Visualization

visualization

ArrowConfig dataclass

Python
ArrowConfig(
    pos: Vec3, vec: Vec3, color: Vec4, is_torque: bool
)

resolve_arrow_coords

Python
resolve_arrow_coords(
    mj_model: MjModel,
) -> tuple[Vec3, Vec3, float]

Calculates the 'from' and 'to' points and width for an arrow.

Source code in src/mujoco_mojo/visualization.py
Python
def resolve_arrow_coords(
    self, mj_model: mujoco.MjModel
) -> tuple[Vec3, Vec3, float]:
    """Calculates the 'from' and 'to' points and width for an arrow."""
    # calculate native scaling
    v_map = mj_model.vis.map
    v_scale = mj_model.vis.scale
    stat = mj_model.stat

    if self.is_torque:
        mag_scale = v_map.torque
        width = v_scale.jointwidth * stat.meansize
    else:
        mag_scale = v_map.force
        width = v_scale.forcewidth * stat.meansize

    # normalize length by mean body mass
    scaled_vec = self.vec * (mag_scale / max(stat.meanmass, 1e-6))
    start = np.asarray(self.pos)
    return start, start + scaled_vec, width