# scipy.spatial.transform.Rotation.from_quat¶

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

Initialize from quaternions.

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

Parameters: quat : array_like, shape (N, 4) or (4,) Each row is a (possibly non-unit norm) quaternion in scalar-last (x, y, z, w) format. normalized : boolean, optional If False, input quaternions are normalized to unit norm before being stored. If True, quaternions are assumed to already have unit norm and are stored as given. Default is False. rotation : Rotation instance Object containing the rotations represented by input quaternions.

References

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)


By default, quaternions are normalized before initialization.

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


If unit norms are ensured, skip the normalization step.

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