bundles / scipy latest / scipy / spatial / transform / _rotation / Rotation / __mul__
function
scipy.spatial.transform._rotation:Rotation.__mul__
source: build-install/usr/lib/python3.14/site-packages/scipy/spatial/transform/_rotation.py:1719
Signature
def __mul__(self, other: Rotation) → RotationSummary
Compose this rotation with the other.
Extended Summary
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
other: `Rotation` instanceObject containing the rotations to be composed with this one. Note that rotation compositions are not commutative, so
p * qis generally different fromq * p.
Returns
composition: `Rotation` instanceThis 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.
Examples
from scipy.spatial.transform import Rotation as R import numpy as np✓
p = R.from_quat([0, 0, 1, 1]) q = R.from_quat([1, 0, 0, 1]) p.as_matrix() q.as_matrix() 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() q.as_quat()✗
array([[ 0.38268, 0. , 0. , 0.92388],
[-0.37282, 0. , 0.37282, 0.84971]])
r = p * q
✓r.as_quat()
✗array([[ 0.2706 , 0.2706 , 0.65328, 0.65328],
[ 0.33721, -0.26362, 0.26362, 0.86446]])
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 r = p * q r.shape✓
(5, 6)
Aliases
scipy.spatial.transform.Rotation.__mul__