SciPy

scipy.spatial.transform.Rotation.__mul__

Rotation.__mul__(other)[source]

Compose this rotation with the other.

If p and q are two rotations, then the composition of ‘q followed by p’ is equivalent to p * q. In terms of DCMs, the composition can be expressed as p.as_dcm().dot(q.as_dcm()).

Parameters
otherRotation instance

Object containing the rotaions to be composed with this one. Note that rotation compositions are not commutative, so p * q is different from q * p.

Returns
compositionRotation instance

This function supports composition of multiple rotations at a time. The following cases are possible:

  • Either p or q contains a single rotation. In this case composition contains the result of composing each rotation in the other object with the single rotation.

  • Both p and q contain N rotations. In this case each rotation p[i] is composed with the corresponding rotation q[i] and output contains N rotations.

Examples

>>> from scipy.spatial.transform import Rotation as R

Composition of two single rotations:

>>> p = R.from_quat([0, 0, 1, 1])
>>> q = R.from_quat([1, 0, 0, 1])
>>> p.as_dcm()
array([[ 0., -1.,  0.],
       [ 1.,  0.,  0.],
       [ 0.,  0.,  1.]])
>>> q.as_dcm()
array([[ 1.,  0.,  0.],
       [ 0.,  0., -1.],
       [ 0.,  1.,  0.]])
>>> r = p * q
>>> r.as_dcm()
array([[0., 0., 1.],
       [1., 0., 0.],
       [0., 1., 0.]])

Composition of two objects containing equal number of rotations:

>>> p = R.from_quat([[0, 0, 1, 1], [1, 0, 0, 1]])
>>> q = R.from_rotvec([[np.pi/4, 0, 0], [-np.pi/4, 0, np.pi/4]])
>>> p.as_quat()
array([[0.        , 0.        , 0.70710678, 0.70710678],
       [0.70710678, 0.        , 0.        , 0.70710678]])
>>> q.as_quat()
array([[ 0.38268343,  0.        ,  0.        ,  0.92387953],
       [-0.37282173,  0.        ,  0.37282173,  0.84971049]])
>>> r = p * q
>>> r.as_quat()
array([[ 0.27059805,  0.27059805,  0.65328148,  0.65328148],
       [ 0.33721128, -0.26362477,  0.26362477,  0.86446082]])