# Rotate coordinate system

I am reading yaw, pitch and roll values from a mobile device. If I perform a yaw of 90 degrees and then any roll, the roll value is not changing but only the pitch value. That is because the device is always referencing to a non turning coordinate system. Therefore a turn around the z axis (yaw) of 90 degrees causes the pitch and roll readings to be "switched". Therefore lifting the iPhone at the top where the selfie camera is located is now no more changing the pitch value but the roll value as the referencing coordinate system is still the same. I can't change that programmatically.

So is there a mathematical way to turn the coordinate system with the device without loosing the turn value around for example the z-axis? I think I can do this by getting the transformation matrix and multiply it with its inverse but keeping the rotation around z. However how can I do this for combined rotations around all three axis? Because with combined rotations every element(yaw, pitch and roll) is already containing a part of the other two elements because the axis are switched with every rotation. Has anyone an idea??? Help is greatly appreciated!

• I am sure this is already answered here: math.stackexchange.com/questions/2390852/… – Brethlosze Oct 22 '17 at 13:29
• Thank you, @hyprfrcb . The provided link shows how to generate a transformation matrix from yaw, pitch and roll. I have no problem doing this. If I followed the description I end up having the same matrix I already have in which my two axes are still switched when the third is rotated by 90 degrees. – Ulbertain Oct 22 '17 at 14:01
• So you still have the problem? DO you have any graphics? – Brethlosze Oct 23 '17 at 3:37
• Yes I am still trying to figure it out @hyprfrcb ... Check my other question for more info about the issue : stackoverflow.com/questions/46863891/… – Ulbertain Oct 23 '17 at 18:20