spacepy.coordinates.quaternionToMatrix

spacepy.coordinates.quaternionToMatrix(Qin, scalarPos='last', normalize=True)[source]

Given an input quaternion, return the equivalent rotation matrix.

The output has one more axis than the input (the last axis) and the shape is otherwise unchanged, allowing multi-dimensional quaternion input.

Parameters
Qinarray_like

input quaternion or array of quaternions, must be normalized.

Returns
outarray_like

Rotation matrix

Other Parameters
scalarPosstr

Location of the scalar component of the input quaternion, either ‘last’ (default) or ‘first’.

normalizeTrue

Normalize input quaternions before conversion (default). If False, raises error for non-normalized.

Raises
NotImplementedError

for invalid values of scalarPos.

ValueError

for inputs which are not valid normalized quaternions or arrays thereof: if the size doesn’t end in (4), if the quaternion is not normalized and normalize is False.

Notes

New in version 0.2.2.

Implementation of the Euler–Rodrigues formula.

Examples

>>> import spacepy.coordinates
>>> spacepy.coordinates.quaternionToMatrix([0.5, 0.5, 0.5, 0.5])
array([[ 0.,  0.,  1.],
       [ 1.,  0.,  0.],
       [ 0.,  1.,  0.]])