bundles / scipy latest / scipy / spatial / transform / _rotation / Rotation / from_quat
staticmethod
scipy.spatial.transform._rotation:Rotation.from_quat
source: build-install/usr/lib/python3.14/site-packages/scipy/spatial/transform/_rotation.py:433
Signature
def from_quat(quat: ArrayLike, *, scalar_first: bool = False) → RotationSummary
Initialize from quaternions.
Extended Summary
Rotations in 3 dimensions can be represented using unit norm quaternions [1].
The 4 components of a quaternion are divided into a scalar part w and a vector part (x, y, z) and can be expressed from the angle theta and the axis n of a rotation as follows
w = cos(theta / 2) x = sin(theta / 2) * n_x y = sin(theta / 2) * n_y z = sin(theta / 2) * n_z
There are 2 conventions to order the components in a quaternion:
scalar-first order --
(w, x, y, z)scalar-last order --
(x, y, z, w)
The choice is controlled by scalar_first argument. By default, it is False and the scalar-last order is assumed.
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
quat: array_like, shape (..., 4)Each row is a (possibly non-unit norm) quaternion representing an active rotation. Each quaternion will be normalized to unit norm.
scalar_first: bool, optionalWhether the scalar component goes first or last. Default is False, i.e. the scalar-last order is assumed.
Returns
rotation: `Rotation` instanceObject containing the rotations represented by input quaternions.
Examples
from scipy.spatial.transform import Rotation as R
✓r = R.from_quat([0, 0, 0, 1]) r.as_matrix() r = R.from_quat([1, 0, 0, 0], scalar_first=True) r.as_matrix()✓
array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])
It is possible to initialize multiple rotations in a single object by
passing an N-dimensional array:
r = R.from_quat([[ [1, 0, 0, 0], [0, 0, 0, 1] ]]) r.as_quat() r.as_quat().shape✓
(1, 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() 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.70711, 0.70711])
Aliases
scipy.spatial.transform.Rotation.from_quat