NiBabel

Access a cacophony of neuro-imaging file formats

Next topic

nibabel.eulerangles.angle_axis2euler

This Page

Reggie -- the one

nibabel.euleranglesΒΆ

Module implementing Euler angle rotations and their conversions

See:

See also: Representing Attitude with Euler Angles and Quaternions: A Reference (2006) by James Diebel. A cached PDF link last found here:

http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.110.5134

Euler’s rotation theorem tells us that any rotation in 3D can be described by 3 angles. Let’s call the 3 angles the Euler angle vector and call the angles in the vector alpha, beta and gamma. The vector is [ alpha, beta. gamma ] and, in this description, the order of the parameters specifies the order in which the rotations occur (so the rotation corresponding to alpha is applied first).

In order to specify the meaning of an Euler angle vector we need to specify the axes around which each of the rotations corresponding to alpha, beta and gamma will occur.

There are therefore three axes for the rotations alpha, beta and gamma; let’s call them i j, k.

Let us express the rotation alpha around axis i as a 3 by 3 rotation matrix A. Similarly beta around j becomes 3 x 3 matrix B and gamma around k becomes matrix G. Then the whole rotation expressed by the Euler angle vector [ alpha, beta. gamma ], R is given by:

R = np.dot(G, np.dot(B, A))

See http://mathworld.wolfram.com/EulerAngles.html

The order G B A expresses the fact that the rotations are performed in the order of the vector (alpha around axis i = A first).

To convert a given Euler angle vector to a meaningful rotation, and a rotation matrix, we need to define:

  • the axes i, j, k
  • whether a rotation matrix should be applied on the left of a vector to be transformed (vectors are column vectors) or on the right (vectors are row vectors).
  • whether the rotations move the axes as they are applied (intrinsic rotations) - compared the situation where the axes stay fixed and the vectors move within the axis frame (extrinsic)
  • the handedness of the coordinate system

See: http://en.wikipedia.org/wiki/Rotation_matrix#Ambiguities

We are using the following conventions:

  • axes i, j, k are the z, y, and x axes respectively. Thus an Euler angle vector [ alpha, beta. gamma ] in our convention implies a alpha radian rotation around the z axis, followed by a beta rotation around the y axis, followed by a gamma rotation around the x axis.
  • the rotation matrix applies on the left, to column vectors on the right, so if R is the rotation matrix, and v is a 3 x N matrix with N column vectors, the transformed vector set vdash is given by vdash = np.dot(R, v).
  • extrinsic rotations - the axes are fixed, and do not move with the rotations.
  • a right-handed coordinate system

The convention of rotation around z, followed by rotation around y, followed by rotation around x, is known (confusingly) as “xyz”, pitch-roll-yaw, Cardan angles, or Tait-Bryan angles.

Functions

angle_axis2euler(theta, vector[, is_normalized]) Convert angle, axis pair to Euler angles
euler2angle_axis([z, y, x]) Return angle, axis corresponding to these Euler angles
euler2mat([z, y, x]) Return matrix for rotations around z, y and x axes
euler2quat([z, y, x]) Return quaternion corresponding to these Euler angles
mat2euler(M[, cy_thresh]) Discover Euler angle vector from 3x3 matrix
quat2euler(q) Return Euler angles corresponding to quaternion q