Not understanting the result of a relative transformation

I have the following set of coordinate frames (translations are not important in this case):

• $w$, the reference frame.
• $l$, a "left" reference frame. Rotated $-20\deg$ around $Y_l$ (axes $Y$ of frame $l$), rotated $-12\deg$ around $X_l$, and translated along $-X_w$.
• $r$, a "right" reference frame, similar to left. Rotated $20\deg$ around $Y_r$, rotated $-12\deg$ around $X_r$, and translated along $X_w$.

I hope the diagram makes it more clear: The rotation matrices that describe the orientations are ($R_{w,l}$ represents rotation from $w$ to $l$, values are rounded):

$R_{w,l} = \left[ \begin{array}{{c}} 0.94&0&-0.34\\ 0.07&0.98&0.2\\ 0.33&-0.21&0.92 \end{array}\right]$, $R_{w,r} = \left[ \begin{array}{{c}} 0.94&0&0.34\\ -0.07&0.98&0.2\\ -0.33&-0.21&0.92 \end{array}\right]$

The problem comes when I want to know the relative rotation between $l$ and $r$: $R_{l,r}$. If I am not mistaken, this rotation can be computed from the ones I have:

$R_{l,r} = R_{l,w}R_{w,r} = R^T_{w,l}R_{w,r}$.

When I do this, I get the following result:

$R_{l,r} = \left[ \begin{array}{{c}} 0.77&0&0.64\\ 0&1&0\\ -0.64&0&0.77 \end{array}\right]$

Which in Euler angles to just a rotation of $40\deg$ around $Y$ (not sure which $Y$!). However, this does not make sense to me, because the only $Y$ I can use for this to make sense is $Y_w$.

What am I missing?

Expected result

I tried directly with the Euler angles. To convert from $l$ to $r$, one should do (starting in $l$):

$R_x(12\deg) \rightarrow R_y(20\deg) \rightarrow R_y(20\deg) \rightarrow R_x(-12\deg)$

Which are computed as matrices as follows:

$R_{l,r} = R_x(12\deg)R_y(40\deg)R_x(-12\deg)$

And this provides the following result:

$R_{l,r} = \left[ \begin{array}{{c}} 0.77&-0.13&0.63\\ 0.13&0.99&0.05\\ -0.63&0.05&0.77 \end{array}\right]$

Which makes way more sense, and actually represents the rotation from $l$ to $r$.

Wow, this is a spectacularly detailed question, so thanks for that, welcome to Robotics, and I'm sorry you're having trouble with this.

The trouble that you're having is that you're inverting the wrong matrix! Allow me to explain.

You have two matrices, $R_r$ and $R_{\ell}$. To be more specific, as you have, these are the matrices that convert world coordinates to the right or left frames, respectively. I understand the notation is generally understood to be $R_{w, r}$, etc., but this might be easier if you use an arrow:

$$R_{w\: \rightarrow \:r} \\$$

Now, if you put this in an equation, you might see how the notation is a little "backwards," if you will:

$$s_r = \left(R_{w\: \rightarrow \:r}\right) s_w$$

To get a point $s$ converted from world coordinates to the right frame, you multiply the world point, $s_w$, by the transform $R_{w\: \rightarrow \:r}$. But maybe you can see how the arrow points in the wrong direction - matrix multiplication happens right to left! It would be a little clearer still to reverse the arrow:

$$R_{r\: \leftarrow \:w} \\$$

There! Now consider:

$$s_r = \left(R_{r\: \leftarrow \:w}\right) s_w \\$$

Hopefully, you see that this is still converting world coordinates to right coordinates. The matrix itself doesn't change (yet), I'm just altering the way I'm displaying it to help illustrate where the problem lies.

Now, recall that you have a left and right transform, which can now be represented as:

$$s_{\ell} = \left(R_{\ell \: \leftarrow \:w} \right) s_w \\ s_r = \left(R_{r \: \leftarrow \:w} \right) s_w \\$$

Now you want the full transform from the right frame to the left frame. You can't just apply the transforms together, because now it's obvious that they don't "stack" together:

$$\left(R_{\ell \: \leftarrow \:w} \right) \left(R_{r \: \leftarrow \:w} \right) \\$$

What you did was to invert the transform between world and left frames, but you can see with the new notation that this is the wrong answer:

$$R_{w \: \leftarrow \: \ell} = \left( R_{\ell \: \leftarrow \: w} \right)^{-1} = \left( R_{\ell \: \leftarrow \: w} \right)^{T}\\$$

If you try the inverted left transform, now you have:

$$\left(R_{w \: \leftarrow \: \ell} \right) \left(R_{r \: \leftarrow \:w} \right) \\$$

If you try instead to invert the right transform, now you have:

$$R_{w \: \leftarrow \: r} = \left( R_{r \: \leftarrow \: w} \right)^{-1} = \left( R_{r \: \leftarrow \: w} \right)^{T}\\$$

Which gets you:

$$\left(R_{\ell \: \leftarrow \:w} \right) \left(R_{w \: \leftarrow \: r} \right) \\$$

Now you can provide a point in the right frame, convert it to world frame, then convert to the left frame.

$$s_{\ell} = \left(R_{\ell \: \leftarrow \:w} \right) \left(R_{w \: \leftarrow \: r} \right) s_r \\$$

Numerically, this gets you the expected answer. Hope this helps!

• Thank you so much for the quick and detailed answer. However, I have to say I do not see the difference between your reply and mine. Isn't what you call $R_{l \leftarrow w}$ the same as I call $R^T_{w,l} = R_{l,w}$? That is, the rotation of frame $l$ with respect to $w$, expressed in $w$ (what is the rotation of $l$ seen from $w$).
– Javi
Jun 4 '18 at 8:53
• @JaviV - No, that's where the notation is confusing. $R_{w,l}$ is the conversion from world to "Left" frames. When you transpose (invert) it, you convert from "Left" to world frames. Now you have $R_{l,w}$, but when you put it with the other matrix, you get $R_{l,w} R_{w,r}$. However, this first converts a coordinate from the world frame to "Right" frame, then from the left frame to the world frame. Jun 5 '18 at 12:44
• It looks like it should work, because the $w$s are in the middle, so it *looks* like they "cancel," but the don't, because that notation is backwards. This is why I introduced the arrow notation I did - to highlight the fact that it's backwards. What you have when you you write $R_{l,w} R_{w,r}$ is actually Output = World $\leftarrow$ Left $\leftarrow$ Right $\leftarrow$ World. You don't go "through" the world frame here. Keep the "forward" left transform and invert the right transform and you get Output = Left $\leftarrow$ World $\leftarrow$ World $\leftarrow$ Right; this is the right way. Jun 5 '18 at 12:50
• I must be having some mental breakdown here. First, when I try your solution in code, it matches in numbers with the expected result, but not in signs. And the solution that is closer is to the expected is $R_{w,r}R{l,w}$. Also, I always understood as following: when you are transforming frames, multiplication is to the right, and when converting points, to the left. In fact, robot kinematics follows this. There, T1 is from 0 to 1, T2 from 1 to 2, etc. How is this different then (because you are going left when converting frames)?
– Javi
Jun 6 '18 at 11:37
• @JaviV - The signs might be a directional problem; it wasn't clear to me which way you're trying to go, but $R_{\ell,r} = R_{r,\ell}^{-1} = R_{r,\ell}^T$. Regarding directionality of matrix multiplication, the link you posted is wrong. Here is a PDF Page 9 says, "Transform matrices must be premultiplied; The first transformation you want to perform will be at the far right, just before the point." (Emphasis added). Page 13-22 walks through building a composite transform matrix to rotate about an arbitrary point. Jun 7 '18 at 14:58