Transform.as_rotation#
- Transform.as_rotation(
- representation: Literal['quat', 'matrix', 'rotvec', 'mrp', 'euler', 'davenport'] | None = None,
- *args,
- **kwargs,
Return the rotation component as a SciPy
Rotationor any of its representations.The current
matrixis first decomposed to extract the rotation component and then returned with the specified representation.Note
This method depends on the
scipypackage which must be installed to use it.- Parameters:
- representation
str,optional Representation of the rotation.
'quat': Represent as a quaternion usingas_quat(). Returns a length-4 vector.'matrix': Represent as a 3x3 matrix usingas_matrix().'rotvec': Represent as a rotation vector usingas_rotvec().'mrp': Represent as a Modified Rodrigues Parameters (MRPs) vector usingas_mrp().'euler': Represent as Euler angles usingas_euler().'davenport': Represent as Davenport angles usingas_davenport().
If no representation is given, then an instance of
scipy.spatial.transform.Rotationis returned by default.- *args
Arguments passed to the
Rotationmethod for the specified representation.- **kwargs
Keyword arguments passed to the
Rotationmethod for the specified representation.
- representation
- Returns:
- output
scipy.spatial.transform.Rotation|np.ndarray Rotation object or array depending on the representation.
- output
See also
rotation_matrix,rotation_axis_angle,decomposeGet this transform’s rotation component without using SciPy.
rotate,rotate_x,rotate_y,rotate_z,rotate_vectorCompose a rotation matrix.
Examples#
Download Python source code | Download Jupyter notebook
Create a rotation matrix and initialize a Transform from it.
>>> import numpy as np
>>> import pyvista as pv
>>> matrix = [[0, -1, 0], [1, 0, 0], [0, 0, 1]]
>>> transform = pv.Transform(matrix)
Represent the rotation as scipy.spatial.transform.Rotation instance.
>>> rot = transform.as_rotation()
>>> type(rot)
<class 'scipy.spatial.transform._rotation.Rotation'>
Represent the rotation as a quaternion.
>>> rot = transform.as_rotation('quat')
>>> rot
array([0. , 0. , 0.70710678, 0.70710678])
Represent the rotation as a rotation vector. The vector has a direction
(0, 0, 1) and magnitude of pi/2.
>>> rot = transform.as_rotation('rotvec')
>>> rot
array([0. , 0. , 1.57079633])
Represent the rotation as a Modified Rodrigues Parameters vector.
>>> rot = transform.as_rotation('mrp')
>>> rot
array([0. , 0. , 0.41421356])
Represent the rotation as x-y-z Euler angles in degrees.
>>> rot = transform.as_rotation('euler', 'xyz', degrees=True)
>>> rot
array([ 0., 0., 90.])
Represent the rotation as extrinsic x-y-z Davenport angles in degrees.
>>> rot = transform.as_rotation(
... 'davenport', np.eye(3), 'extrinsic', degrees=True
... )
>>> rot
array([-1.27222187e-14, 0.00000000e+00, 9.00000000e+01])