skrobot.coordinates.math.rotation_distance

skrobot.coordinates.math.rotation_distance(R1, R2, check=True)[source]

Return the geodesic distance between two rotations.

Computes the geodesic distance (shortest path on SO(3)) between two rotation matrices. This is equivalent to the angle of the relative rotation R1.T @ R2.

Parameters:
  • R1 (list or numpy.ndarray) – First rotation matrix (3x3) or axis-angle vector (3,).

  • R2 (list or numpy.ndarray) – Second rotation matrix (3x3) or axis-angle vector (3,).

  • check (bool, optional) – If True (default), validate that inputs are proper rotation matrices. Set to False for better performance when inputs are known to be valid.

Returns:

angle – Geodesic distance in radians (0 to pi).

Return type:

float

Examples

>>> import numpy as np
>>> from skrobot.coordinates.math import rotation_distance
>>> rotation_distance(np.eye(3), np.eye(3))
0.0
>>> rotation_distance(
...     np.eye(3),
...     np.array([[0, 0, 1], [0, 1, 0], [-1, 0, 0]]))
1.5707963267948966
>>> # Also accepts axis-angle vectors
>>> rotation_distance([0, 0, 0], [0, 0, np.pi/2])
1.57079...