Our portable devices are getting more and more fun to use, due in part to new generations of augmented and virtual reality applications. If you look at the software source code at the heart of these AR & VR apps, you’ll discover a common component: a mathematical model relating the position and orientation of your portable device within an earth frame of reference. I first touched on this back in my post Degrees of freedom vs. axes.Now I want to dig into some of the ways to mathematically model orientation. Perhaps the three most common are Euler angles, rotation matrices and quaternions. Today’s discussion will focus on the Euler angles and rotation matrices. We’ll follow up with quaternions in a future posting.
x_{e} = x_{b} cos(Y) – y_{b} sin(Y) | (Eqn. 1) |
y_{e} = x_{b} sin(Y) + y_{b} cos(Y) | (Eqn. 2) |
In matrix form: | |
A_{earth} = C(-ψ) A_{body} | (Eqn. 3) |
The inverse of which is: | |
A_{body} = C(ψ) A_{earth} | (Eqn. 4) |
where A_{earth} and A_{body} are of the form [x y]^{T} and:
(Eqn. 5) | |
(Eqn. 6) |
All other relationships included in this discussion can be similarly mapped to a diagram of the rotation. The analysis also extends naturally to three dimensions. If A_{earth} and A_{body} are of the form [x y z]^{T}, then:
(Eqn. 7) | |
(Eqn. 8) |
We will use the three dimensional form in the remainder of this discussion. In both two and three dimensional cases, C(ψ) and C(-ψ) are known as rotation matrices.
Notice that C(ψ) is the transpose of C(-ψ), and vice-versa: C(ψ)^{T} = C(-ψ). This is a special property of all rotation matrices. You can reverse the sense of rotation simply by taking the transpose of the original matrix.
C(ψ) C(-ψ) = I_{3×3} | (Eqn. 9) |
Where I_{3×3} is simply the identity matrix:
(Eqn. 10) |
This also implies that the inverse of a rotation matrix is simply its own transpose:
C(ψ)^{-1} = C(ψ)^{T} | (Eqn. 11) |
Similar relationships hold for rotations in the X-Z (about the Y axis) plane:
x_{e} = x_{b} cos(θ) + z_{b} sin(θ) | (Eqn. 12) |
z_{e} = – x_{b} sin(θ) + z_{b} cos(θ) | (Eqn. 13) |
A_{earth} = C(-θ) A_{body} | (Eqn. 14) |
A_{body} = C(θ) A_{earth} | (Eqn. 15) |
(Eqn. 16) | |
(Eqn. 17) |
and for rotations in the Z-Y (about the X axis) plane:
y_{e} = y_{b} cos(Φ) – z_{b} sin(Φ) | (Eqn. 18) |
z_{e} = y_{b} sin(Φ) + z_{b} cos(Φ) | (Eqn. 19) |
A_{earth} = C(-Φ) A_{body} | (Eqn. 20) |
A_{body} = C(Φ) A_{earth} | (Eqn. 21) |
(Eqn. 22) | |
(Eqn. 23) |
Phi, Theta and Psi (Φ, θ and ψ) rotations in sequence can map a point in any right-hand-rule (RHR) 3-dimensional space into any other RHR 3-dimensional space.
A rotation from earth by body frame about Z, then Y then X axes (the “aerospace” sequence) is represented by:
(Eqn. 24) |
The composite rotation matrix is computed simply by multiplying the three individual matrices in the specified order. Consistent with the discussion above, the inverse of this expression is:
(Eqn. 25) |
Collectively, Φ, θ and ψ are known as Euler angles. You may also see Φ, θ and ψ referred to as “roll”, “pitch” and “yaw” respectively. The subscript “RPY” in the expression above refers to roll-pitch-yaw, and “YPR” refers to yaw-pitch-roll.
Euler angles are sometimes sub-divided into “Tait-Bryan” angles (in which rotations occur about all three axes) and “Proper” Euler angles (in which the first and third axes of rotation are the same). Regardless of which type you use, it is important to specify the order of the rotations — which IS significant. In the table below, the right-most rotation is performed first, consistent with the matrix operations that will be required to implement the rotation. Possible variants are:
Alpha | Angles | Comments | |
YRP | ψ-Φ-θ | Tait-Bryan angles
(AKA Nautical or Cardan angles) |
All of these are sometimes referred to simply as “Euler Angles” |
YPR | ψ-θ-Φ | ||
PYR | θ-ψ-Φ | ||
PRY | θ-Φ-ψ | ||
RYP | Φ-ψ-θ | ||
RPY | Φ-θ-ψ | ||
RYR | Φ-ψ-Φ | Proper Euler Angles | |
RPR | Φ-θ-Φ | ||
PYP | θ-ψ-θ | ||
PRP | θ-Φ-θ | ||
YRY | ψ-Φ-ψ | ||
YPY | ψ-θ-ψ |
A full discussion of Euler angles is beyond the scope of this article. But some key points you need to take away are:
If you define a “reference orientation” for any object, then you can define its current orientation as some rotation relative to that reference. Tracking orientation over time is then equivalent to tracking rotation from that reference over time. Because Euler angles are relatively easy to visualize, they enjoyed early popularity in a number of fields. But because of the shortcomings listed above, anyone who has used them extensively invariably learns to despise them — I know I do!
Rotation matrices don’t require a master’s degree to be able to use them. Anyone with a college freshman geometry class under their belt can figure them out. They don’t have the ambiguities associated with Euler angles, and can be found at the heart of many algorithms.
4 Comments
i am not able to see the images , opening in new tab shows forbidden error
The web page shows OK from my end. I suspect the page is being filtered by your company’s firewall.
I can’t view all images neither; I guess it has nothing to do with the firewall. The images were uploaded to FSL site instead of NXP one.
For example the Figure 1 is at:
http://blogs.freescale.com/wp-content/uploads/2014/11/post-10809-Figure1.jpg
which may still be up inside FSL, but definitely not from outside.
Is there a way to fix this?
All, I confirm that the images are not visible outside the NXP network. I’ve asked our blogging team to investigate. In the meantime, I will post pages from the upcoming Version 7.00 Sensor Fusion Users Manual (to https://community.nxp.com/community/sensors/sensorfusion) which contain the same material.
Sorry for the problems.
Mike