SciPy

scipy.spatial.transform.Rotation.from_quat

classmethod Rotation.from_quat(quat, normalized=None)[source]

Initialize from quaternions.

3D rotations can be represented using unit-norm quaternions [1].

Parameters
quatarray_like, shape (N, 4) or (4,)

Each row is a (possibly non-unit norm) quaternion in scalar-last (x, y, z, w) format. Each quaternion will be normalized to unit norm.

normalized

Deprecated argument. Has no effect, input quat is always normalized.

Deprecated since version 1.4.0.

Returns
rotationRotation instance

Object containing the rotations represented by input quaternions.

References

1

https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

Examples

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

Initialize a single rotation:

>>> r = R.from_quat([1, 0, 0, 0])
>>> r.as_quat()
array([1., 0., 0., 0.])
>>> r.as_quat().shape
(4,)

Initialize multiple rotations in a single object:

>>> r = R.from_quat([
... [1, 0, 0, 0],
... [0, 0, 0, 1]
... ])
>>> r.as_quat()
array([[1., 0., 0., 0.],
       [0., 0., 0., 1.]])
>>> r.as_quat().shape
(2, 4)

It is also possible to have a stack of a single rotation:

>>> r = R.from_quat([[0, 0, 0, 1]])
>>> r.as_quat()
array([[0., 0., 0., 1.]])
>>> r.as_quat().shape
(1, 4)

Quaternions are normalized before initialization.

>>> r = R.from_quat([0, 0, 1, 1])
>>> r.as_quat()
array([0.        , 0.        , 0.70710678, 0.70710678])