# Rotating a set of anges (pitch/yaw/roll) by another set of angles (pitch/yaw/roll)

I want to rotate a set of angles (pitch/yaw/roll) by another set of angles (pitch/yaw/roll). By using Google I only found information about rotating a vector by angles, which is not what I need. Examples: (disregarding signs)

- (0/90/0) rotated by (90/0/0) -> (90/0/90)
- (0/0/90) rotated by (90/0/0) -> (90/90/0)


For simplicity I just created examples with angles of 90°, but I am looking for a method that can also do this with odd angles. What method works for this? Is this possible to do with rotation matrices?

## 2 Answers

This is a problem that 3D animation software has to deal with all the time, namely when an object's coordinate system is related to another object's coordinate system rather than the global coordinate system. In the general case, there may be arbitrarily many such coordinate systems each adding their own pitch/yaw/roll to each child object.

The solution used by Blender (https://www.blender.org) is based on Quaternions. Wikipedia explains how quaternions work in this case: https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation. That explanation is perhaps too lengthy to be copied here (though it can be if that's the only way to validly "answer" the question).

• I have looked up on some turorials about Quaternions, but I really have trouble understanding how I can use them for the rotation around 3 axes - and how can I get the vector v of the rotation axis that is described in the last 3 arguments of the quaternion? Could you provide a link or formulas to do this or point me in the right direction of using the quaternions? – domisum Sep 11 '15 at 22:08
• If you look at the RSpincalc module (cran.r-project.org/web/packages/RSpincalc/RSpincalc.pdf) you will see you can create an orientation expressed as an Euler Angle (EA xyz <=> x(roll) y(pitch) z(yaw)), convert to quaternion, then update the x(roll) y(pitch) z(yaw) values of the quaternion via the function Qrot, then convert back to Euler Angles or Euler Vectors. – Michael Tiemann Sep 12 '15 at 1:55

It's impossible to do with rotation matrices (and arguably impossible to do at all). Why? Here are two pitch-roll-yaw sequences:

A = (180/180/180)

B = (0/0/0)


They amount to exactly the same thing (don't move at all).

Why is this a problem? Suppose you do $A$ twice. Of course, the result is still "don't move at all". But should the answer to your question be $A$ or $B$? Both are correct. And because of that, it's likely that no single clean procedure will produce a continuously-varying output as you continuously vary the two inputs.

What about the claim about matrices? Well, the matrices corresponding to $A$ and $B$ are both the identity, so you definitely can't distinguish them.

BTW: This is closely related to the problem of gimbal lock, which plagues many mechanical systems.

• Well, this problem only arises at certain specific combinations of angles (as does gimbal lock). In the rest of the configuration space you should be fine. – Ivan Neretin Sep 11 '15 at 18:21
• If you just want to extract pitch/yaw/roll from a rotation matrix, I put code for that in the 3D transformations chapter of *Computer Graphics: Principles and Practice, 3rd Edition". I'm sure it's written down well elsewhere, too. – John Hughes Sep 11 '15 at 20:25