# Decomposition of a Rotation Matrix

1. Jul 26, 2012

### QuickLoris

Hey guys! I'm new here, so forgive me if I'm posting in the wrong section.
I recently picked up a book on robotics and it had a section about rotation matrices. I'm having a difficult time with the decomposition of rotation matrices. Everywhere I look, I can find the the equations for the roll, pitch, and yaw, but there's never any derivation.

Can someone explain how you get them or point me in the direction of where I can learn?

Last edited: Jul 27, 2012
2. Jul 27, 2012

### chiro

Hey QuickLoris and welcome to the forums.

The basic idea for deriving these matrices has to do with with cos(x+y) = cos(x)cos(y) - sin(x)sin(y) and sin(x+y) = sin(x)cos(y) + cos(x)sin(y).

Now lets say we are rotating around the z-axis: the z co-ordinate won't change but the x and y probably will.

Define y = rsin(a) and x = rcos(a) where r is the length of the vector in 2D and a is the angle (decomposition into polar).

Now we give an angle b that we want to rotate around: our new rotated vector will be y' = rsin(a+b) and x' = rcos(a+b): we need to find x' and y' in terms of x and y.

Now expanding this out we get y' = rsin(a+b) = rsin(a)cos(b) + rcos(a)sin(b) and x' = rcos(a+b) = rcos(a)cos(b) - rsin(a)sin(b).

But y = rsin(a) and x = rcos(a) so substituting in we get:

y' = ycos(b) + xsin(b) and x' = xcos(b) - ysin(b)

In matrix form this gives us for x,y:

[cos(b) -sin(b)] [x] = [x']
[sin(b) cos(b)] [y] [y']

For 3D, we have the condition that the z point doesn't change since we are rotating about the z-axis so for this case we get:

[cos(b) -sin(b) 0]
[sin(b) cos(b) 0]
[ 0 0 1]

as our rotation matrix.

You can do the same thing for the other rotations in the x-z and y-z planes to get your other matrices.

To derive the general axis angle you do the same sort of thing.

3. Jul 27, 2012

### QuickLoris

I'm still wondering though, about how the angles are derived straight from the matrix. In the book it has the example of a global roll-pitch-yaw rotation matrix

GQB = QZ,γQY,βQX,α
=
[cβcγ -cαsγ+cγsαsβ sαsγ+cαcγsβ ]
[cβsγ cαcγ+sαsβsγ -cγsα+cαsβsγ ]
[-sβ cβsα cαcβ ]

Suppose that rij indicates the element of row i and column j of the roll-pitch-yaw rotation matrix, then the roll angle is:

α = tan-1(r32/r33)

the pitch angle is:
β = -sin-1(r31)

and the yaw angle is:
γ = tan-1(r31/r11)

I don't see the link between the roll-pitch-yaw angle equations and the elements of the matrix. In other words, why those elements?

My understanding is that the rows 1,2, and 3 correspond to the I, J, and K of the global frame and the columns correspond to i, j, and k or the local frame. But if we're looking at the angle for roll, why are we looking into the j and k components of the Z direction?

Should I look into a particular subject matter to understand these things?

4. Jul 27, 2012

### chiro

Derive the individual matrices and then multiply them together: I have derived one, but you can derive the rest through exactly the same ideas, with the note that you will rotate about the x-z and y-z planes.

Then do matrix multiplication in the order you have written above and compare the two results: basically you are composing functions by doing Q(x) then Q(y) and finally Q(z) [composition is right to left in terms the order of application]

5. Jul 28, 2012

### D H

Staff Emeritus
A word of caution: Your book must use a different convention than do I. For a roll-pitch-yaw (XYZ) sequence, I use
$$\begin{bmatrix} \cos\beta\cos\gamma & \cos\alpha\sin\gamma+\sin\alpha\sin\beta\cos\gamma & \sin\alpha\sin\gamma-\cos\alpha\sin\beta\cos\gamma \\ -\cos\beta\sin\gamma & \cos\alpha\cos\gamma-\sin\alpha\sin\beta\sin\gamma & \sin\alpha\cos\gamma+\cos\alpha\sin\beta\sin\gamma \\ \sin\beta & -\sin\alpha\cos\beta & \cos\alpha\cos\beta \end{bmatrix}$$
I'm not saying your book is wrong. It's just convention, the distinction boiling down to $\begin{bmatrix}\cos\theta & \sin\theta \\ -\sin\theta & \cos\theta \end{bmatrix}$ versus $\begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix}$ Using my convention (I'll just make a mess of things if I use your book's convention), let's take a look at that roll/pitch/yaw sequence but treat the upper right 2x2 submatrix as noise:
$$\begin{bmatrix} \cos\beta\cos\gamma & \cdots & \cdots \\ -\cos\beta\sin\gamma & \cdots & \cdots \\ \sin\beta & -\sin\alpha\cos\beta & \cos\alpha\cos\beta \end{bmatrix}$$
Here's my convention for a roll/yaw/pitch (XZY) sequence, reducing some of the elements to ellipses (...):
$$\begin{bmatrix} \cos\beta\cos\gamma & \cdots & \cdots \\ -\sin\beta & \cos\alpha\cos\beta & \sin\alpha\cos\beta \\ \cos\beta\sin\gamma & \cdots & \cdots \end{bmatrix}$$
Finally, here's the astronomical ZXZ sequence:
$$\begin{bmatrix} \cdots & \cdots & \sin\beta\sin\gamma \\ \cdots & \cdots & \sin\beta\cos\gamma \\ \sin\alpha\sin\beta & -\cos\alpha\sin\beta & \cos\beta \end{bmatrix}$$
Note that there is always some key row that involves just the first two angles of the sequence, a key column that involves the last two angles only, and a key element at the intersection of that key row and column that involves the middle angle only. The reason is pretty simple. When written as a product of three matrices, the leftmost matrix will always have one trivial row that comprises a one and two zeros, while the rightmost matrix will always have one trivial column that comprises a one and two zeros. The trivial row in the leftmost matrix and trivial column in the rightmost matrix dictate the key row, key column, and key element in the product. For example, for an XYZ sequence it is the third row, first column; for a XZY sequence it is the second row, first column; and for a ZXZ sequence it is the third row, third column. That key element is $\sin\beta$, $-\sin\beta$, or $\cos\beta$. The first two pertain to aerodynamics sequences (XYZ, XZY, ...), the sign depending on whether the sequence is an even or odd permutation of XYZ. The value of $\cos\beta$ pertains to the six astronomical sequences (ZXZ, ...).

6. Jul 29, 2012

### QuickLoris

Thanks to the both of you!
DH,your explanation was exactly what I was looking for!
Can you recommend a textbook (I'm guessing I need a general Linear Algebra book) so I can delve into the theory behind this kind of stuff? I really like knowing the details when it comes to things like this.

7. Jul 29, 2012

### BackEMF

A good book by all accounts (I haven't read it yet myself) is this: Quaternions and Rotation Sequences. It may be a bit too advanced at the moment. Keep it for later reference maybe, something to work toward!

8. Jul 29, 2012

### QuickLoris

Thanks BackEMF, I added it to my shopping list.