Axes and Euler Angles

Overview

Euler angles describe an orientation as three successive rotations about coordinate axes. ksl/axis.h names the twelve possible axis sequences. For KSL_AXIS_XYZ with angles \((\alpha, \beta, \gamma)\), the rotation matrix is

\[R = R_x(\alpha)\, R_y(\beta)\, R_z(\gamma)\]

that is, a rotation about x, then about the new y axis, then about the newest z axis. Six sequences use three different axes (XYZ, ZYX, …; often called Tait-Bryan or roll-pitch-yaw angles) and six repeat the first axis (ZXZ, ZYZ, …; the classical Euler angles). The comment after each value in ksl_axis_enum_t lists its axes as indices, 0 = x, 1 = y, 2 = z.

Euler angles are easy to read and to specify by hand, which makes them common in input files and user interfaces. They have two drawbacks:

  • Singular orientations (gimbal lock). When the middle rotation lines up the first and third axes (\(\beta = \pm 90^\circ\) for the three-axis sequences, \(\beta = 0\) or \(180^\circ\) for the repeated-axis ones), only the sum or difference of the first and third angles is defined, and the angles change very quickly near that orientation.

  • Wrap-around. Each angle is only defined up to a multiple of \(2\pi\).

ksl_mat3x3_getEulerAngles() (see 3x3 Matrices) accepts the angles of a nearby previous orientation as an optional last argument and returns the solution closest to them, so a sequence of orientations gives continuous angles. For computation, rotation matrices or quaternions (see Quaternions) avoid both problems. [10] discusses rotation sequences in detail.

The functions that convert between rotation matrices and Euler angles, ksl_mat3x3_getEulerAngles() and ksl_mat3x3_setFromEulerAngles(), are described with the 3x3 matrices. The Euler angle types are in ksl/eulerangles.h, which must be included separately.

Axis sequences

ksl_axis_enum_t

Order of the three rotation axes in an Euler angle sequence. The comment after each value gives the axis indices (0 = x, 1 = y, 2 = z).

ksl_axis_getVector()

convert ksl_axis_enum_t to a vector of ints

ksl_axis_getEulerAngles()

Look up the Euler angle sequence for a triple of axis indices.

enum ksl_axis_enum_t

Order of the three rotation axes in an Euler angle sequence. The comment after each value gives the axis indices (0 = x, 1 = y, 2 = z).

Values:

enumerator KSL_AXIS_XYZ
enumerator KSL_AXIS_YZX
enumerator KSL_AXIS_ZXY
enumerator KSL_AXIS_XZY
enumerator KSL_AXIS_YXZ
enumerator KSL_AXIS_ZYX
enumerator KSL_AXIS_XYX
enumerator KSL_AXIS_XZX
enumerator KSL_AXIS_YXY
enumerator KSL_AXIS_YZY
enumerator KSL_AXIS_ZXZ
enumerator KSL_AXIS_ZYZ
enumerator KSL_AXIS_INVALID
ksl_vec3i_t ksl_axis_getVector(ksl_axis_enum_t axisType)

convert ksl_axis_enum_t to a vector of ints

ksl_axis_enum_t ksl_axis_getEulerAngles(ksl_vec3i_t angles)

Look up the Euler angle sequence for a triple of axis indices.

Parameters:
  • angles – [in] the axes of the three rotations, 0 = x, 1 = y, 2 = z; for example {2, 1, 0} for z-y-x

Returns:

the matching ksl_axis_enum_t value, or KSL_AXIS_INVALID if the triple is not one of the 12 valid sequences

Euler angle rates

ksl_axis_getEulerRateMatrix()

Matrix that maps Euler angle rates to angular velocity.

ksl_axis_eulerRatesToOmega()

Angular velocity from Euler angle rates: \(\underline{\omega} = E\dot{\underline{\theta}}\) .

ksl_axis_omegaToEulerRates()

Euler angle rates from angular velocity: \(\dot{\underline{\theta}} = E^{-1}\underline{\omega}\) .

void ksl_axis_getEulerRateMatrix(const ksl_axis_enum_t axisType, const ksl_vec3_t *angles, ksl_mat3x3_t *E)

Matrix that maps Euler angle rates to angular velocity.

For the sequence \(R = R_i(\theta_0)R_j(\theta_1)R_k(\theta_2)\) of ksl_mat3x3_setFromEulerAngles(), the angular velocity of the rotated frame relative to the reference frame, in the coordinates of the reference frame, is

\[ \underline{\omega} = \dot{\theta}_0\,\underline{u}_i + R_i(\theta_0)\bigl(\dot{\theta}_1\, \underline{u}_j + R_j(\theta_1)\,\dot{\theta}_2\,\underline{u}_k\bigr) = E\,\dot{\underline{\theta}}, \qquad E = \begin{bmatrix} \underline{u}_i & R_i\underline{u}_j & R_iR_j\underline{u}_k \end{bmatrix}, \]

with \(\underline{u}_i\) the unit vector of axis i. In the coordinates of the rotated frame the angular velocity is \(R^{T}\underline{\omega}\). E is singular when the first and third axes are aligned (gimbal lock): at \(\cos\theta_1 = 0\) for the six Tait-Bryan sequences and at \(\sin\theta_1 = 0\) for the six proper Euler sequences.

Parameters:
  • axisType – [in] Euler angle sequence

  • angles – [in] Euler angles \(\theta_0, \theta_1, \theta_2\)

  • E – [out] rate matrix

void ksl_axis_eulerRatesToOmega(const ksl_axis_enum_t axisType, const ksl_vec3_t *angles, const ksl_vec3_t *rates, ksl_vec3_t *omega)

Angular velocity from Euler angle rates: \(\underline{\omega} = E\dot{\underline{\theta}}\).

See ksl_axis_getEulerRateMatrix(); the angular velocity is in the coordinates of the reference frame.

Parameters:
  • axisType – [in] Euler angle sequence

  • angles – [in] Euler angles

  • rates – [in] Euler angle rates \(\dot{\underline{\theta}}\)

  • omega – [out] angular velocity \(\underline{\omega}\)

int ksl_axis_omegaToEulerRates(const ksl_axis_enum_t axisType, const ksl_vec3_t *angles, const ksl_vec3_t *omega, ksl_vec3_t *rates)

Euler angle rates from angular velocity: \(\dot{\underline{\theta}} = E^{-1}\underline{\omega}\).

See ksl_axis_getEulerRateMatrix(); the angular velocity is in the coordinates of the reference frame.

Parameters:
  • axisType – [in] Euler angle sequence

  • angles – [in] Euler angles

  • omega – [in] angular velocity \(\underline{\omega}\)

  • rates – [out] Euler angle rates \(\dot{\underline{\theta}}\)

Returns:

0, or nonzero if E is singular (gimbal lock), in which case rates is not set

Euler angle types

These types are in ksl/eulerangles.h, which must be included separately.

ksl_eulerangles_t

A sequence of three double precision Euler angles and the axis order they are applied in.

ksl_euleranglesf_t

Single precision version of ksl_eulerangles_t.

struct ksl_eulerangles_t

A sequence of three double precision Euler angles and the axis order they are applied in.

struct ksl_euleranglesf_t

Single precision version of ksl_eulerangles_t.