Translating a 3D point from one frame to another

1.6k Views Asked by At

Me and my friend have ran into trubbels with translating a point in a 3D-space from one cartesian coordinate system to another.

In this case we have 3 coordinate systems called the Base-frame, h-frame and b-frame (see picture below). From the Base-frame we rotate with $\pi$ around the Base-frame x-axis in order to reach the h-frame. This is done with the following transformation matrix:

$ T_{base}^h = \begin{bmatrix} 1,\ \ 0,\ \ 0,\ \ 0\\0,-1,\ \ 0,\ \ 0\\0,\ \ 0,-1,\ \ 0\\0,\ \ 0,\ \ 0,\ \ 1 \end{bmatrix}$

When this has been done we rotate from the h-frame to the b-frame by rotating around the h-frame x-axis with $\frac{\pi}{2}$ with the following matrix:

$ T_{h}^b = \begin{bmatrix} 1,\ \ 0,\ \ 0,\ \ 0 \\ 0,\ \ 0,-1,\ \ 0\\ 0,\ \ 1,\ \ 0,\ \ 0\\0,\ \ 0,\ \ 0,\ \ 1 \end{bmatrix}$

We then want to express a coordinate, expressed in the Base-frame, say $coord_{base} = [1;1;0;1]$, in the b-frame (last 1 just for size). With the knowledge of the frames orientation the point [1;1;0;1] expressed in the Base-frame, should become [1;0;1;1] in the b-frame. To get this point with the help of our matrices, we perform the following calculation

$coord_{b} = T_{base}^h \ \ T_{h}^b \ \ coord_{base}$

this, however, yields the point [1;0;-1], and not [1;0;1] as expected. Why? Are we multiplying in the wrong order? Creating the rotation matrices in the wrong order? Are we missing something obvious here?

Picture of frames and their rotation

Grateful for all help we can get!

2

There are 2 best solutions below

0
On

To expand a bit on greg’s comment, yes, you’ve got the matrices in the wrong order. Think about it this way: After transforming $\mathbf x_{base}$ into the $h$-frame, you have $T_{base}^h\mathbf x_{base}$. You then transform this into the $b$-frame, you multiply this by the next transformation matrix, getting $T_h^b(T_{base}^h\mathbf x_{base})$.

More generally, if you’re representing points as column vectors, then you left-multiply by the transformation matrix and the transformation cascade grows leftward; if you’re using row vectors, you right-multiply by the matrix and the cascade grows rightward.

0
On

Thank you for your replies!

However, even when if we change the order of the multiplication from $T_{base}^{h} \ T_{h}^b \ coord_{base}$ to $T_{h}^{b} \ T_{base}^{h} \ coord_{base}$, we still get the same (wrong) answer, which is $coord_b = [1;0;-1]$. This made us believe that the frames somehow got rotated wrongly along the way, and that the b-frame especially had been flip $\pi$ around the x-axis. That would explain the coordinate we get. After redoing the calculations in Matlab, as seen below, we did however find out that this was NOT the case. The b-frame is oriented the same way as in the picture provided earlier. How come the point doesn't "understand" this?

%Creation of transformation matrices

T_base_h = [1, 0, 0, 0 ; 0, -1, 0, 0 ; 0, 0, -1, 0 ; 0, 0, 0, 1];

T_h_b = [1, 0, 0, 0; 0, 0, -1, 0; 0, 1, 0, 0; 0, 0, 0, 1];

% Base frame

coord_base = [1;1;0;1]

frame_base = [1,0,0; 0,1,0; 0,0,1];

% h-frame

coord_h = T_base_h * coord_base;

frame_h = frame_base * T_base_h(1:3,1:3)

% b-frame

coord_b = T_h_b * coord_h;

frame_b = frame_h * T_h_b(1:3,1:3)