pyvista.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
Rotation
or any of its representations.The current
matrix
is first decomposed to extract the rotation component and then returned with the specified representation.Note
This method depends on the
scipy
package 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.Rotation
is returned by default.- *args
Arguments passed to the
Rotation
method for the specified representation.- **kwargs
Keyword arguments passed to the
Rotation
method for the specified representation.
- representation
- Returns:
scipy.spatial.transform.Rotation
|np.ndarray
Rotation object or array depending on the representation.
See also
Examples
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() >>> rot <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 ofpi/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])