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
and the axis of a rotation as follows:
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 used.
The mapping from quaternions to rotations is
two-to-one, i.e. quaternions q and -q, where -q simply
reverses the sign of each component, represent the same spatial
rotation.
Parameters:
canonical : bool, default False
Whether to map the redundant double cover of rotation space to a
unique “canonical” single cover. If True, then the quaternion is
chosen from {q, -q} such that the w term is positive. If the w term
is 0, then the quaternion is chosen such that the first nonzero
term of the x, y, and z terms is positive.
scalar_first : bool, optional
Whether the scalar component goes first or last.
Default is False, i.e. the scalar-last order is used.
The resulting shape of the quaternion is always the shape of the Rotation
object with an added last dimension of size 4. E.g. when the Rotation object
contains an N-dimensional array (N, M, K) of rotations, the result will be a
4-dimensional array: