## Rotation matrices: global vs. local

Recently I came across the problem of rotating an object in 3d realtime application around its local axis. To give the answer instantly: It is done like rotation around world axis but in reverse order of rotations.

Usually you will use the standard rotation matrices around X, Y, Z axis to rotate a point or vector around the respective world axis. Instead rotating around a local axis rotates the object around an axis that already has been rotated before. So local rotation only makes sense for consecutive rotations. If you only do one rotation on an object that has not been rotated so far, local and global axis are equal.

Local rotation is equal to world rotation in reverse order. Why? This can be explained by looking at the way rotation matrices change vector basis. According to this article we observed that a rotation matrix does a vector basis change from the rotated basis it represents to the standard basis or more general to the basis the coordinates of the vector or point you rotate are related to. This is the reason why the standard rotation matrices always do a world like rotation. They do not transform the vector or point to its rotated coordinate system. Local rotation instead has to describe a rotation in respect to the coordinate system of the before applied rotation. Consider two rotations $R_{1}$ and $R_{2}$ applied to a vector $v$: $R_{2}\cdot R_{1}\cdot v=v‘$

In that order the rotation $R_{1}$ would be applied first and $R_{2}$ afterwards. Now we want $R_{2}$ to perform a local rotation. Local means here that $R_{2}$ is done in respect to the rotated vector basis $R_{1}$ represents. In order to transform coordinates into the vector basis of a rotation matrix we have to apply the inverted rotation matrix. For this example this looks like this: $R_{2}\cdot R_{1}^{-1} \cdot R_{1}\cdot v=v‘$

But from the moment that we apply $R_{1}^{-1}$ we are working in the coordinate system of $R_{1}$. So we have to transform back to the original coordinate system $v$ was defined in by applying $R_{1}$ once again after doing the local rotation: $R_{1} \cdot R_{2}\cdot R_{1}^{-1} \cdot R_{1}\cdot v=v‘$

This is the full term now, but we see that $R_{1}^{-1} \cdot R_{1}$ equals the identity matrix and thus can be cut out. This gives the final result: $R_{1}\cdot R_{2}\cdot v=v‘$

So the order of rotations has just changed in order to apply $R_{2}$ as a local rotation, what proves the above given solution to the problem. This change of order gives us another hint on consecutive rotations: If you have a matrix multiplication representing consecutive rotations you can always interpret it in both directions: From left to right (like you read) every rotation is applied on local axis. From right to left every rotation is applied on world (global) axis. Again: These are possible interpretations of a series of rotations. The nice thing here is that we still only use the standard rotation matrices and do not have extra costs but just change the order.

Author: Michael Keutel | 11.05.2015