In the last post, we covered 2D rotation matrices, which allow us to convert coordinates from one coordinate system to another coordinate system that’s rotated by some angle *θ*. Previously, we notated the original coordinate system *XY* and the rotated coordinate system *X’Y’*. In this post, we’ll begin dealing with a larger number of coordinate systems. Adding a prime for each additional coordinate system would be impractical and inconvenient, so we’ll use numerical subscripts to differentiate between coordinate systems, instead.

Referring to the image above, the *X _{0}Y_{0}* coordinate system is equivalent to the

*XY*coordinate system from the previous post, and will generally represent the “global” coordinate system we’re most interested in. The

*X*coordinate system is equivalent to the

_{1}Y_{1}*X’Y’*coordinate system from the previous post, and

*θ*is equivalent to

_{0}*θ*. The rotation matrix to convert from the

*X*system to the

_{1}Y_{1}*X*would be

_{0}Y_{0}\(

[R] = \left[ \begin{matrix} cos\theta_0 & -sin\theta_0 \\

sin\theta_0 & cos\theta_0 \end{matrix} \right]

\)

Converting a vector defined in the *X _{1}Y_{1}* system to the

*X*system would look like this:

_{0}Y_{0}\(

\left\{ \begin{matrix} x_0 \\ y_0 \end{matrix} \right\} =

\left[ \begin{matrix} cos\theta_0 & -sin\theta_0 \\

sin\theta_0 & cos\theta_0 \end{matrix} \right]

\left\{ \begin{matrix} x_1 \\ y_1 \end{matrix} \right\}

\)

A Euclidean transformation matrix that can perform both rotation and translation looks similar to this, but contains an additional row and and an additional column:

\(

[T] = \left[ \begin{matrix} cos\theta_0 & -sin\theta_0 & 0 \\

sin\theta_0 & cos\theta_0 & 0 \\

0 & 0 & 1 \end{matrix} \right]

\)

The last column of the first row provides the translation in *x* along the *X _{0}* axis, and the last column of the second row provides the translation in

*y*along the

*Y*axis. For pure rotation without translation, these elements are equal to zero. The last row of the transformation matrix always contains zeros except for the final element, which is always a one. Similarly, the position vector for a point intended to be used with a transformation matrix must contain an additional dummy coordinate that’s always equal to one:

_{0}\(

\left\{ \begin{matrix} x_0 \\ y_0 \\ 1 \end{matrix} \right\} =

\left[ \begin{matrix} cos\theta_0 & -sin\theta_0 & 0 \\

sin\theta_0 & cos\theta_0 & 0 \\

0 & 0 & 1 \end{matrix} \right]

\left\{ \begin{matrix} x_1 \\ y_1 \\ 1 \end{matrix} \right\}

\)

Consider an example where there *is* translation, say, for instance, some distance *a* along *X _{0}* and some distance

*b*along

*Y*:

_{0}The equation and transformation matrix in this case would be

\(

\left\{ \begin{matrix} x_0 \\ y_0 \\ 1 \end{matrix} \right\} =

\left[ \begin{matrix} cos\theta_0 & -sin\theta_0 & a \\

sin\theta_0 & cos\theta_0 & b \\

0 & 0 & 1 \end{matrix} \right]

\left\{ \begin{matrix} x_1 \\ y_1 \\ 1 \end{matrix} \right\}

\)

If it’s not apparent why this is the case, try working through the matrix multiplication to see how these additional elements affect the resulting coordinates. A simple example to consider might be

\(

\left\{ \begin{matrix} x_1 \\ y_1 \\ 1 \end{matrix} \right\} =

\left\{ \begin{matrix} 0 \\ 0 \\ 1 \end{matrix} \right\}

\)

i.e., the origin of the second coordinate system, for which you should simply obtain *x _{0} = a* and

*y*.

_{0}= bThe true value in using transformation matrices is the ability to chain together multiple transformation matrices. In other words, if you have one coordinate system that’s defined in another coordinate system (by its rotation and translation relative to that other coordinate system), which, in turn, is defined in yet another coordinate system, and so on, you can obtain the coordinates of some point in the desired coordinate system by multiplying the transformation matrices of all the intervening coordinate systems. For example, consider the following case, which contains three coordinate systems:

Here, the *X _{1}Y_{1}* system (drawn in red) is defined by its rotation and translation relative to the

*X*system (drawn in black), specifically:

_{0}Y_{0}\(

\left[ ^0 T_1 \right] =

\left[ \begin{matrix} cos\theta_0 & -sin\theta_0 & a \\

sin\theta_0 & cos\theta_0 & b \\

0 & 0 & 1 \end{matrix} \right]

\)

where the notation on the left-hand side indicates that the transformation matrix is converting *from* the *X _{1}Y_{1}* system

*to*the

*X*system. Further, the

_{0}Y_{0}*X*system (drawn in blue) is defined by its rotation (by some angle

_{2}Y_{2}*θ*) and translation (

_{1}*c*in the

*X*direction and

_{1}*d*in the

*Y*direction) relative to the

_{1}*X*system, i.e.:

_{1}Y_{1}\(

\left[ ^1 T_2 \right] =

\left[ \begin{matrix} cos\theta_1 & -sin\theta_1 & c \\

sin\theta_1 & cos\theta_1 & d \\

0 & 0 & 1 \end{matrix} \right]

\)

To convert coordinates from the *X _{2}Y_{2}* system to the

*X*system, the transformation matrices are successively multiplied:

_{0}Y_{0}\(

\left[ ^0 T_2 \right] = \left[ ^0 T_1 \right] \left[ ^1 T_2 \right]

\)

If it’s not clear why this works, consider the following example. Let’s say we have some position vector defined in the *X _{2}Y_{2}* system, which we’ll write as

**r**, and we’d like to obtain its coordinates in terms of the

_{2}*X*system, which we’ll write as

_{0}Y_{0}**r**. This is the same as writing:

_{0}\(

\textbf{r}_\textbf{0} = \left[ ^0 T_1 \right] \left[ ^1 T_2 \right] \textbf{r}_\textbf{2}

\)

The term \(\left[ ^1 T_2 \right] \textbf{r}_\textbf{2}\) on the right-hand side just says “convert the coordinates **r _{2}** from the

*X*system to the

_{2}Y_{2}*X*system,” i.e., \(\textbf{r}_\textbf{1} = \left[ ^1 T_2 \right] \textbf{r}_\textbf{2}\). Then, to convert

_{1}Y_{1}**r**to

_{1}**r**, we multiply by \(\left[ ^0 T_1 \right] \). Note that the order in which we multiply the transformation matrices matters—matrix multiplication is not commutative, and multiplying them in the wrong order will affect the result.

_{0}Let’s look at a concrete example to attain some intuition for how to apply these concepts. Suppose we have a robot arm with two segments, each controlled by a revolute joint. At the end of the second segment is the robot arm’s end effector—this end effector might be some sort of claw, manipulator, or gripper that’s designed to grab things.

You can liken this to a human arm, where joint 1 would be the shoulder, joint 2 would be the elbow, and the end effector would be the hand. Knowing only the length of each segment (which will always remain constant) and the angular displacement of each joint (which we might control using motors), how can we determine the position of the end effector in 2D space? In this example, joint 1 (the “shoulder joint”) isn’t necessarily located at the center of our primary coordinate system, but is offset by some distance in *X _{0}* and

*Y*.

_{0}One way to approach this is to define a coordinate system at each joint. The *X _{1}Y_{1}* system at the first joint is offset from the

*X*system by an angle

_{0}Y_{0}*θ*, a distance

_{0}*a*in

*X*, and a distance

_{0}*b*in

*Y*:

_{0}where *θ _{0}* corresponds to the angular displacement of the joint, and the first segment is aligned with the

*X*axis. The transformation matrix for this coordinate system is

_{1}\(

\left[ ^0 T_1 \right] =

\left[ \begin{matrix} cos\theta_0 & -sin\theta_0 & a \\

sin\theta_0 & cos\theta_0 & b \\

0 & 0 & 1 \end{matrix} \right]

\)

We might then define the next coordinate system, *X _{2}Y_{2}*, to be located at the second joint a distance

*c*along the

*X*axis (i.e., the first segment, or the “upper arm,” is of length

_{1}*c*), and offset by a rotation

*θ*corresponding to the angular displacement of the second joint.

_{1}The transformation matrix for this *X _{2}Y_{2}* system, relative to the

*X*system, is

_{1}Y_{1}\(

\left[ ^1 T_2 \right] =

\left[ \begin{matrix} cos\theta_1 & -sin\theta_1 & c \\

sin\theta_1 & cos\theta_1 & 0 \\

0 & 0 & 1 \end{matrix} \right]

\)

Note that the offset in *Y _{1}* is zero, since the coordinate system is positioned in line with the the “upper arm” along

*X*. Finally, suppose that the length of the second segment (the “forearm”), which lies along

_{1}*X*, is

_{2}*d*.

Then the coordinates of the end effector in the *X _{2}Y_{2}* system,

**r**, are given by

_{2}\(

\textbf{r}_\textbf{2} =

\left\{ \begin{matrix} d \\ 0 \\ 1 \end{matrix} \right\}

\)

Remember that we want the coordinates of the end effector in the *X _{0}Y_{0}* system, i.e.,

**r**. We obtain this by multiplying the position vector from the

_{0}*X*system by the transformation matrices in the correct order:

_{2}Y_{2}\(

\textbf{r}_\textbf{0} = \left[ ^0 T_1 \right] \left[ ^1 T_2 \right] \textbf{r}_\textbf{2}

\)

Or, writing the right-hand side out in full:

\(

\textbf{r}_\textbf{0} =

\left[ \begin{matrix} cos\theta_0 & -sin\theta_0 & a \\

sin\theta_0 & cos\theta_0 & b \\

0 & 0 & 1 \end{matrix} \right]

\left[ \begin{matrix} cos\theta_1 & -sin\theta_1 & c \\

sin\theta_1 & cos\theta_1 & 0 \\

0 & 0 & 1 \end{matrix} \right]

\left\{ \begin{matrix} d \\ 0 \\ 1 \end{matrix} \right\}

\)

Carrying out the matrix multiplication is left as an exercise for you, the reader.

There you have it—a crash course in Euclidean transformation matrices. If some of these concepts haven’t quite stuck, you may want to reread the post, working through the examples with pen and paper until you’ve internalized them. If you’re comfortable with 2D Euclidean transformations, consider reading up on 3D Euclidean transformations, if you’re not already familiar with them. These topics will likely be revisited and applied in future posts.