Combinations of transformations

From Robotics
Jump to: navigation, search
← Back: Homogeneous coordinates Overview: Transformations Next: Inverse transformation

In the previous subarticle homogeneous coordinates and transformation matrices for translation and rotation around the three axes are introduced:


\mathbf{Trans}(p_x,p_y,p_z), \quad\mathbf{Rot}(x,\varphi), \quad \mathbf{Rot}(y,\varphi), \quad\mathbf{Rot}(z,\varphi)

These transformation matrices can be combined by multiplying them.

Consider the following transformation matrix \mathbf{T} that corresponds to the multiplication of several single transformation matrices (also denoted with \mathbf{T} for simplification):


\mathbf{T}=\mathbf{T}_n...\mathbf{T}_3\mathbf{T}_2\mathbf{T}_1

Combinations of transformations are always applied from right to left. So in the example case, \mathbf{T}_1 is applied first. Then on this result, transformation \mathbf{T}_2 is applied and so on. The left transformation matrix \mathbf{T}_n is finally multiplied with the result of all the previous transformations.

Transformorder.png

As already stated for multiplication of matrices, different multiplication orders lead to different results. If only translations are regarded, the order does not matter, because translation is actually vector addition and vector addition is commutative. Rotation however depends on the current input coordinates. Descriptively seen, rotation is always applied around the origin of the global coordinate system or around an axis intersecting with the origin, respectively. So the rotational part is depending on the respective current coordinates. Different orders of transformations result in different input coordinates for each transformation.


The following example shows descriptively as well as computationally, that the order of transformations is important (see figure on the right). Consider a local coordinate frame positioned in the origin, whose axes are oriented parallel to the global coordinate axes. The related initial position vector \vec{\mathbf{q}}_0 is a zero vector. A translation matrix \mathbf{Trans}(0,0,1) and a rotation matrix \mathbf{Rot}(x,90^\circ) are to be applied to this local frame. So two different orders of the two transformations are possible.

The upper three subfigures on the right show the first case. The local frame is first rotated around the x-axis and then translated on the z-axis. The result is shown in the top right subfigure. Computationally \vec{\mathbf{q}}_0 is first pre-multiplied with \mathbf{Rot}(x,90^\circ) and then pre-multiplied with \mathbf{Trans}(0,0,1):

\begin{align}
\vec{\mathbf{q}}_1&=
\left[\begin{array}{c}
x_1\\
y_1\\
z_1\\
1
\end{array}\right]=
\mathbf{Trans}(0,0,1)\mathbf{Rot}(x,90^\circ)\vec{\mathbf{q}}_0 =
\left[\begin{array}{cccc}
1 & 0 & 0 & 0\\
0 & 1 & 0 & 0\\
0 & 0 & 1 & 1\\
0 & 0 & 0 & 1
\end{array}\right]
\left[\begin{array}{cccc}
1 & 0 & 0 & 0\\
0 & 0 & -1 & 0\\
0 & 1 & 0 & 0\\
0 & 0 & 0 & 1
\end{array}\right]
\left[\begin{array}{c}
x_0\\
y_0\\
z_0\\
1
\end{array}\right] \\ &=
\left[\begin{array}{cccc}
1 & 0 & 0 & 0\\
0 & 0 & -1 & 0\\
0 & 1 & 0 & 1\\
0 & 0 & 0 & 1
\end{array}\right]
\left[\begin{array}{c}
x_0\\
y_0\\
z_0\\
1
\end{array}\right]=
\left[\begin{array}{c}
x_0\\
-z_0\\
y_0+1\\
1
\end{array}\right]=
\left[\begin{array}{c}
0\\
0\\
1\\
1
\end{array}\right]
\end{align}

The lower three subfigures on the right show the second case. The local frame is first translated on the z-axis and then rotated around the x-axis. The result is shown in the lower right subfigure. Computationally \vec{\mathbf{q}}_0 is first pre-multiplied with \mathbf{Trans}(0,0,1) and then pre-multiplied with \mathbf{Rot}(x,90^\circ):

\begin{align}
\vec{\mathbf{q}}_2&=
\left[\begin{array}{c}
x_2\\
y_2\\
z_2\\
1
\end{array}\right]=
\mathbf{Rot}(x,90^\circ)\mathbf{Trans}(0,0,1)\vec{\mathbf{q}}_0 =
\left[\begin{array}{cccc}
1 & 0 & 0 & 0\\
0 & 0 & -1 & 0\\
0 & 1 & 0 & 0\\
0 & 0 & 0 & 1
\end{array}\right]
\left[\begin{array}{cccc}
1 & 0 & 0 & 0\\
0 & 1 & 0 & 0\\
0 & 0 & 1 & 1\\
0 & 0 & 0 & 1
\end{array}\right]
\left[\begin{array}{c}
x_0\\
y_0\\
z_0\\
1
\end{array}\right] \\ &=
\left[\begin{array}{cccc}
1 & 0 & 0 & 0\\
0 & 0 & -1 & -1\\
0 & 1 & 0 & 0\\
0 & 0 & 0 & 1
\end{array}\right]
\left[\begin{array}{c}
x_0\\
y_0\\
z_0\\
1
\end{array}\right]=
\left[\begin{array}{c}
x_0\\
-z_0-1\\
y_0\\
1
\end{array}\right]=
\left[\begin{array}{c}
0\\
-1\\
0\\
1
\end{array}\right]
\end{align}

As you can see from the transformed vectors \vec{\mathbf{q}}_1 and \vec{\mathbf{q}}_2, the transformation order influences the result. In the example there is only one rotation applied. So the orientation of the local frame is the same in both cases. But if there is more than one rotation applied, the resulting orientation differs as well.


The general homogeneous transformation matrix \mathbf{T}, introduced for homogeneous coordinates, consists of a rotation matrix and a translation vector. As shown in the subarticle, multiplication of \mathbf{T} with a vector corresponds to rotating the coordinates first and then adding the translation vector. Written as product of homogeneous transformation matrices, \mathbf{T} equals: (where axis is either x,y or z)


\mathbf{T}=
\left[\begin{array}{ccc|c}
 &  &  &  \\ 
 & \mathbf{R} &  & \vec{\mathbf{p}}\\
 & & & \\ \hline
0 & 0 & 0 & 1
\end{array}\right]=
\mathbf{Trans}(p_x,p_y,p_z)\mathbf{Rot}(axis,\varphi)

As explained for Homogeneous coordinates applying a homogeneous transformation matrix \mathbf{T}_1 is equivalent to first multiplying with the corresponding rotation matrix and then adding the translation vector:


\vec{\mathbf{q}}_1 =
\mathbf{T}_1\vec{\mathbf{q}}_0 \quad \equiv \quad 
\mathbf{R}_1\vec{\mathbf{q}}_0 + \vec{\mathbf{p}}_1

Assume the composed transformation \mathbf{T}_c=\mathbf{T}_2\mathbf{T}_1. So \mathbf{T}_2 is to be applied on the result of the first transformation, which leads to:


\begin{align}
\mathbf{T}_c\vec{\mathbf{q}}_0 = \mathbf{T}_2\mathbf{T}_1\vec{\mathbf{q}}_0 = \mathbf{T}_2\vec{\mathbf{q}}_1 \quad \equiv \quad 
\mathbf{R}_2\vec{\mathbf{q}}_1 + \vec{\mathbf{p}}_2 
&= 
\mathbf{R}_2\Big(\mathbf{R}_1\vec{\mathbf{q}}_0 + \vec{\mathbf{p}}_1\Big)+\vec{\mathbf{p}}_2 \\
&=
\underbrace{\mathbf{R}_2\mathbf{R}_1}_{\mathbf{R}_c}\vec{\mathbf{q}}_0 + \underbrace{\mathbf{R}_2\vec{\mathbf{p}}_1+\vec{\mathbf{p}}_2}_{\vec{\mathbf{p}}_c} \\
&=
\mathbf{R}_c\vec{\mathbf{q}}_0 + \vec{\mathbf{p}}_c 
\end{align}

Thus the multiplication of two general homogeneous transformation matrices is defined as follows:


\begin{align}
\mathbf{T}_c = \mathbf{T}_2\mathbf{T}_1 &= \left[\begin{array}{cccc} & & & \\ & \mathbf{R}_2 &  & \vec{\mathbf{p}}_2 \\ & & & \\ 0 & 0 & 0 & 1\end{array}\right]
\left[\begin{array}{cccc} & & & \\ & \mathbf{R}_1 &  & \vec{\mathbf{p}}_1 \\ & & & \\ 0 & 0 & 0 & 1\end{array}\right] \\
&= 
\left[\begin{array}{cccc} & & & \\ & \mathbf{R}_2\mathbf{R}_1 &  & \mathbf{R}_2\vec{\mathbf{p}}_1+\vec{\mathbf{p}}_2 \\ & & & \\ 0 & 0 & 0 & 1\end{array}\right]
\end{align}

Applet

The following applet can be used to test some combinations of different transformations and see the results in a three-dimensional visualization.


Example: Combinations of transformations
Transformorderexample.png

This example is taken from pages 3-34 and 3-35 of the robotics script. The transformation ^R\mathbf{T}_N of the object frame N with respect to the reference frame R is defined as follows:


^R\mathbf{T}_N=\mathbf{Rot}(y,90^\circ)\mathbf{Trans}(0,0,a)\mathbf{Rot}(x,90^\circ)\mathbf{Trans}(0,a,0)


When ^R\mathbf{T}_N is applied (see figure on the right), the input coordinates are first translated by a along the y-axis and then rotated by 90 degrees around the x-axis. Then again a translation by a on the z-axis is applied and finally the coordinates are rotated by 90 degrees around the y-axis.

The four transformation matrices are multiplied to obtain the combined transformation matrix (for further intermediate steps have a look in the script on page 3-35):

\begin{align}
^R\mathbf{T}_N &= 
         \mathbf{Rot}(y,90^\circ)\mathbf{Trans}(0,0,a)\mathbf{Rot}(x,90^\circ)\mathbf{Trans}(0,a,0)\\
         &=
         \left[\begin{array}{cccc}
            \cos90^\circ  & 0 & \sin90^\circ   & 0 \\ 
            0         & 1 & 0          & 0 \\
            -\sin90^\circ  & 0 & \cos90^\circ    & 0 \\
            0         & 0 & 0          & 1 \\
         \end{array}\right]
         \cdot
         \left[
         \begin{array}{cccc}
            1 & 0 & 0 & 0 \\ 
            0 & 1 & 0 & 0 \\
            0 & 0 & 1 & a \\
            0 & 0 & 0 & 1\\
         \end{array}
         \right]
         \cdot
         \left[
         \begin{array}{cccc}
            1 & 0          & 0          & 0 \\ 
            0 & \cos90^\circ   & -\sin90^\circ  & 0 \\
            0 & \sin90^\circ   & ~\cos90^\circ  & 0 \\
            0 & 0          & 0          & 1 \\
         \end{array}
         \right]
         \left[
         \begin{array}{cccc}
             1 & 0 & 0 & 0 \\ 
             0 & 1 & 0 & a \\
             0 & 0 & 1 & 0 \\
             0 & 0 & 0 & 1 \\
         \end{array}
         \right]\\
\\
         &= ... \qquad \text{(page 3-35 in the script)}\\ 
\\
&=
\left[\begin{array}{cccc}
            ~~0 & 1 &~~0 &~2a \\ 
            ~~0 & 0 & -1 &~~0 \\
            -1  & 0 &~~0 &~~0 \\
            ~~0 & 0 &~~0 &~~1 \\
\end{array}\right]\\
&=
\left[\begin{array}{cccc}
            \vec{\mathbf{x}} & \vec{\mathbf{y}} & \vec{\mathbf{z}} & \vec{\mathbf{p}}\\
            0    & 0       & 0       &    1 \\
 \end{array}\right]
\end{align}

The above combined matrix corresponds to the four single transformation steps applied in the designated order. As can be seen in the lower right subfigure, the resulting coordinates of the local frame correspond to the translation vector \vec{\mathbf{p}}=[2a,0,0]^T within the combined matrix. The axes of the coordinate frame are oriented like the vectors \vec{\mathbf{x}}, \vec{\mathbf{y}} and \vec{\mathbf{z}} within the matrix.