Expressing local coordinate system by another local coordinate system through global coordinate system

3dcoordinate systemsgeometryrotations

Imagine you have a 3D global coordinate system, arbitrary local coordinate system 1, and arbitrary local coordinate system 2.

Available are two rotation matrices that define rotations of local coordinate system 1 (R1) and local coordinate system 2 (R2), both with respect to global coordinate system.

How can I express the rotation of local coordinate system 1 with respect to local coordinate system 2?
I have tried with solution in the link below but didn't get expected results.

https://stackoverflow.com/questions/19621069/3d-rotation-matrix-rotate-to-another-reference-system

Thanks in advance.

Best Answer

Let $\mathbf{R}_1$ describe the rotation from global coordinate system to the first local coordinate system, and $\mathbf{R}_2$ describe the rotation from global coordinate system to the second local coordinate system.

Then, $\mathbf{R}_1^{-1}$ describes the rotation from first local coordinate system back to the global coordinate system, and $\mathbf{R}_2^{-1}$ describes the rotation from the second local coordinate system back to the global coordinate system.

When matrix $\mathbf{R}$ is a pure rotation matrix, it is orthonormal, and its inverse is its transpose, $\mathbf{R}^{-1} = \mathbf{R}^T$.

Let's assume right- or post-multiplication between matrices and vectors. This means that if vector $\vec{v}_g$ in global coordinate system corresponds to vector $\vec{v}_1$ in the first local coordinate system, and to vector $\vec{v}_2$ in the second local coordinate system, then $$\vec{v}_1 = \mathbf{R}_1 \vec{v}_g \tag{1}\label{EQ1}$$ $$\vec{v}_2 = \mathbf{R}_2 \vec{v}_g \tag{2}\label{EQ2}$$ $$\vec{v}_g = \mathbf{R}_1^{-1} \vec{v}_1 \tag{3}\label{EQ3}$$ $$\vec{v}_g = \mathbf{R}_2^{-1} \vec{v}_2 \tag{4}\label{EQ4}$$ We can substitute $\eqref{EQ4}$ into $\eqref{EQ1}$ to get $$\vec{v}_1 = \mathbf{R}_1 \mathbf{R}_2^{-1} \vec{v}_2$$ or $\eqref{EQ3}$ into $\eqref{EQ2}$ to get $$\vec{v}_2 = \mathbf{R}_2 \mathbf{R}_1^{-1} \vec{v}_1$$ This means that to rotate a vector from the first local coordinate system to the second coordinate system, we need to use rotation matrix $\mathbf{R}_{1 \to 2}$, $$\mathbf{R}_{1 \to 2} = \mathbf{R}_2 \mathbf{R}_1^{-1} \tag{5}\label{EQ5}$$ and from second local coordinate system back to first, $\mathbf{R}_{2 \to 1}$, $$\mathbf{R}_{2 \to 1} = \mathbf{R}_1 \mathbf{R}_2^{-1} \tag{6}\label{EQ6}$$ Note that due to both matrices being orthonormal, $$\begin{aligned} \mathbf{R}_{2 \to 1} &= \mathbf{R}_{1 \to 2}^{-1} \\ \mathbf{R}_{1 \to 2} &= \mathbf{R}_{2 \to 1}^{-1} \\ \end{aligned}$$ There is no need to repeat this procedure for every single case. From the above, we can derive a few rules that will help in this kind of situation immensely.

  1. We consider only column vectors, i.e. $\vec{v} = \left [ \begin{matrix} v_1 \\ v_2 \\ v_3 \end{matrix} \right ]$.

  2. We consider only pure rotation and reflection matrices, i.e. orthonormal matrices, for which $\mathbf{R}^{-1} = \mathbf{R}^{T}$, and is the inverse of rotation by $\mathbf{R}$.

  3. We use right- or post-multiplication of vectors for matrix-vector multiplication. This means that to rotate vector $\vec{v}$ by matrix $\mathbf{R}$, we obtain result, or rotated vector $\vec{r}$, using $\vec{r} = \mathbf{R} \vec{v}$.

  4. We can chain rotations by multiplying the rotation matrices. If the matrices are orthonormal, the result is orthonormal as well. The first rotation is the rightmost matrix in the product, and the last rotation is the leftmost matrix in the product.

  5. To calculate the rotation between two local coordinate systems, we "unwind" the starting coordinate system rotations using inverse rotation matrices in the inverse order, followed by the rotation matrixes in the normal order from global coordinate system to the target local coordinate system.


As an example, assume we have two local coordinate systems whose rotations from the global coordinate system are $\mathbf{R}_1$ and $\mathbf{R}_2$, and we have two further local coordinate systems, $\mathbf{R}_{11}$ and $\mathbf{R}_{12}$ on top of (or relative to) $\mathbf{R}_1$, and two further local coordinate systems $\mathbf{R}_{21}$ and $\mathbf{R}_{22}$ on top of (or relative to) $\mathbf{R}_2$.

In other words, vector $\vec{v}_0$ in the global coordinate system corresponds to: $$\begin{aligned} \vec{v}_1 &= \mathbf{R}_1 \vec{v}_0 \\ \vec{v}_2 &= \mathbf{R}_2 \vec{v}_0 \\ \vec{v}_{11} &= \mathbf{R}_{11} \mathbf{R}_1 \vec{v}_0 \\ \vec{v}_{12} &= \mathbf{R}_{12} \mathbf{R}_1 \vec{v}_0 \\ \vec{v}_{21} &= \mathbf{R}_{21} \mathbf{R}_2 \vec{v}_0 \\ \vec{v}_{22} &= \mathbf{R}_{22} \mathbf{R}_2 \vec{v}_0 \\ \end{aligned}$$ then $$\begin{aligned} \mathbf{R}_{1 \to 2} &= \mathbf{R}_2 \mathbf{R}_1^{T} \\ \mathbf{R}_{22 \to 2} &= \mathbf{R}_{22}^{T} \\ \mathbf{R}_{21 \to 12} &= \mathbf{R}_{12} \mathbf{R}_{1} \mathbf{R}_2^{T} \mathbf{R}_{21}^{T} \\ \end{aligned}$$ and so on. Simples!

Note that we could write $\mathbf{R}_{22 \to 2} = \mathbf{R}_2 \mathbf{R}_2^{T} \mathbf{R}_{22}^{T}$, but since $\mathbf{R} \mathbf{R}^{T} = \mathbf{R}^{T} \mathbf{R} = \mathbf{I}$ (identity matrix; "no change") for orthonormal matrices, we can omit the identity or "no change" part, and just use $\mathbf{R}_{22 \to 2} = \mathbf{R}_{22}^{T}$.