NiBabel

Access a cacophony of neuro-imaging file formats

Previous topic

nibabel.quaternions.norm

Next topic

nibabel.quaternions.quat2mat

This Page

Reggie -- the one

nibabel.quaternions.quat2angle_axis

nibabel.quaternions.quat2angle_axis(quat, identity_thresh=None)

Convert quaternion to rotation of angle around axis

Parameters :

quat : 4 element sequence

w, x, y, z forming quaternion

identity_thresh : None or scalar, optional

threshold below which the norm of the vector part of the quaternion (x, y, z) is deemed to be 0, leading to the identity rotation. None (the default) leads to a threshold estimated based on the precision of the input.

Returns :

theta : scalar

angle of rotation

vector : array shape (3,)

axis around which rotation occurs

Notes

A quaternion for which x, y, z are all equal to 0, is an identity rotation. In this case we return a 0 angle and an arbitrary vector, here [1, 0, 0]

Examples

>>> theta, vec = quat2angle_axis([0, 1, 0, 0])
>>> np.allclose(theta, np.pi)
True
>>> vec
array([ 1.,  0.,  0.])

If this is an identity rotation, we return a zero angle and an arbitrary vector

>>> quat2angle_axis([1, 0, 0, 0])
(0.0, array([ 1.,  0.,  0.]))