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 rotation matrices, the composition can be expressed as p.as_matrix() @ q.as_matrix().

Parameters:
otherRotation instance

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

Returns:
compositionRotation instance

This function supports composition of multiple rotations at a time. Composition follows standard numpy broadcasting rules. The resulting Rotation object will have the shape np.broadcast_shapes(p.shape, q.shape). In dimensions with size > 1, rotations are composed with matching indices. In dimensions with only one rotation, the single rotation is composed with each rotation in the other object.

Notes

Array API Standard Support

__mul__ has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

Library

CPU

GPU

NumPy

n/a

CuPy

n/a

PyTorch

JAX

Dask

n/a

See Support for the array API standard for more information.

Examples

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

Composition of two single rotations:

>>> p = R.from_quat([0, 0, 1, 1])
>>> q = R.from_quat([1, 0, 0, 1])
>>> p.as_matrix()
array([[ 0., -1.,  0.],
       [ 1.,  0.,  0.],
       [ 0.,  0.,  1.]])
>>> q.as_matrix()
array([[ 1.,  0.,  0.],
       [ 0.,  0., -1.],
       [ 0.,  1.,  0.]])
>>> r = p * q
>>> r.as_matrix()
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]])

Broadcasting rules apply: >>> p = R.from_quat(np.tile(np.array([0, 0, 1, 1]), (5, 1, 1))) >>> q = R.from_quat(np.tile(np.array([1, 0, 0, 1]), (1, 6, 1))) >>> p.shape, q.shape ((5, 1), (1, 6)) >>> r = p * q >>> r.shape (5, 6)