scipy.spatial.transform.Rotation.from_quat#

classmethod Rotation.from_quat(cls, quat)#

Initialize from quaternions.

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

Advanced users may be interested in the “double cover” of 3D space by the quaternion representation [2]. As of version 1.11.0, the following subset (and only this subset) of operations on a Rotation r corresponding to a quaternion q are guaranteed to preserve the double cover property: r = Rotation.from_quat(q), r.as_quat(canonical=False), r.inv(), and composition using the * operator such as r*r.

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

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

Returns:
rotationRotation instance

Object containing the rotations represented by input quaternions.

References

[2]

Hanson, Andrew J. “Visualizing quaternions.” Morgan Kaufmann Publishers Inc., San Francisco, CA. 2006.

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])