LESSON

# Describing rotation and translation in 2D

#### Transcript

Now let's bring translation into the picture. Coordinate frame A, Coordinate frame B which is translated and rotated with respect to coordinate frame A and a point P. We can represent the point P by a vector with respect to frame B and that vector can be described in terms of its components along the XB and YB axis.

Now we can rotate that vector into a new frame, coordinate frame V, and coordinate frame V has axis which are parallel to coordinate frame A. We've already talked about how to rotate a vector from one coordinate frame to another using a rotation matrix. And as a sanity check that we've written this expression correctly, we noticed that these two Bs are next to each other. That's a good thing.

Now let's describe the origin of coordinate frame V with respect to coordinate frame A and we do that with a vector. That's a vector from A to V. Now we're allowed to add vectors so we can add this vector ATV to the vector VP to obtain the vector that describes the point P with respect to coordinate frame A. We can do that because these two vectors are described with respect to coordinate frames whose axis are parallel to one another. I can substitute one equation into the other and write this. And again because these two coordinate frames are parallel I can write this.

Let's expand the vectors and matrix in this expression and write them in terms of their elements. Now I can pull a little bit of the trick and now write it like this. If you're unsure about this depth, expand out the matrix and convince yourself that they are exactly the same.

Now this expression has got a two-element vector and a three-element vector over here. Let's make things a little bit more symmetric and write it like this. What we've down now is added some zeros and some ones to the bottom row of the matrix. Previously we had a 2x2 rotation matrix. Now we see that that's embedded into the top left corner of a 3x3 matrix. And our vectors which is to have 2 elements now have three elements. We can write this even more succinctly in this form. The notation, the tilde, above the little p indicates that it is a homogeneous factor. It has got three elements not two, and we'll talk about that in just a moment. The point is described with respect to coordinate frame A by a homogeneous vector which we can obtain from the homogeneous vector of the point with respect to coordinate frame B multiplied by this matrix.

The elements of the matrix include the rotation matrix, which is the function of the orientation; Theta, and the translation between the origin of coordinate frame A and coordinate frame B. We have the familiar representation of a vector in a 2-dimensional plane, two numbers A and B. The homogeneous vector has got three elements in it. It's got A and B and an additional element which is set to 1. This we refer to as a homogeneous transformation. It is a 3x3 matrix. The homogeneous transformation matrix T comprises a rotation matrix which is 2x2 and a translation vector which is a 2x1 matrix padded out with a couple of zeros and a one.

This matrix describes a relative pose. It describes the pose B with respect to the pose of A. All of that is encoded in this single 3x3 matrix. A mathematician would say that homogeneous transformation belongs to the special Euclidian group of dimension 2. Symbolically we would say matrix T belongs to the set SE(2).

Finally it's time to start making these abstract concepts real. Pose is just a matrix. Where we had the symbol ksi before we can substitute this 3x3 homogeneous transformation matrix. When we talk about compounding or joining two poses together using the O+ operator, that is exactly the same as multiplying these two homogeneous transformations. We use the O- operator to indicate the negation of a relative pose, and that is simply the inverse of a homogeneous transformation matrix. I mentioned earlier that the inverse of a rotation matrix is equal to its transpose. That is not the case for a homogeneous transformation matrix. You need to perform a proper matrix inverse: invert a 3x3 matrix.

We introduced a dot operator which transforms a vector from one coordinate frame to another. And that is simply the product of the homogeneous transformation matrix and the vector represented in homogeneous form. Remember that the homogeneous vector is obtained from the original vector P, the two vector and we augment or append a one element to that to form a three element vector.

Here we are in MATLAB and we're going to experiment with these 2-dimensional homogeneous transformation matrices. So what I’m going to do is introduce a function called transl2 which creates a homogeneous transformation representing a pure translation, that is a translation of 1 in the x direction and 2 in the y direction.

Previously we saw how to create a 2-dimensional rotation matrix, for instance a rotation of 30 degrees is created like this. We see that this rotation matrix is only 2x2 compared to the 3x3 homogeneous transformation matrix. So I can create a homogeneous transformation matrix equivalent of this rotation by prefixing with the letter T. This function returns a 3x3 homogeneous transformation matrix. We can see the rotation matrix part up in the top left corner. We can see that the translation part of this matrix is equal to zero. This homogeneous transformation matrix represents a pure rotation. Now we can multiply these two together. transl2, multiply it by the rotation part - 30 degrees. And now what I have is a homogeneous transformation which represents a pose. It's got a rotational component and it's got a translational component. Now the toolbox has got a shorthand function to achieve this. I parse in the x and y translational parts; the rotational part and the option to say that that angle is specified in units of degrees. We have exactly the same matrix here.

Now let's plot this particular pose and see what it looks like. And to do that I'm going to create an axis in which to plot, and x is going to vary from 0-5 and y is going to vary from 0-5. I need to set the aspect ratio so that everything looks reasonable, so I'm going to set the axis so that the aspect ratio is square. I'm going to put a hold on because I'm going to plot a few poses. The first pose I'm going to plot I'm going to put into workspace variable T1 and it is the pose that I looked at just a moment ago: 1 in the x direction, 2 in the y direction and the rotation of 30 degrees. There is a homogeneous transformation matrix. Now I'm going to plot that.

To plot that I use the function trplot2. The 2 suffix means that it's for 2-dimensional poses. Parse in the pose represented by the homogeneous transformation. I'm going to plot it as a frame named 1, and I'm going to plot it in the color blue. There are quite a few options there. And there we see the pose plotted. We can see that it does indeed have a translational component; 1 in the x direction, 2 in the y direction. And it is rotated with respect to the world coordinate frame.

I can create another pose quite easily. I can create a pose that has got an offset of 2 in the x direction. 1 in the y direction and no rotation. That's what the homogeneous transformation looks like. Now I'm going to plot that. I'm going to use the function trplot2 again, parse in the homogeneous transformation matrix, and I’m going to plot it as a frame labeled 2. To be different I'm going to plot it as a red colored frame, and here we see the second pose. It's got no rotation. It has got a translational component.

Now I can compose 2 of these poses. I’m going to say pose 3 is equal to pose 1 compounded with pose 2. That's what the transformation matrix look like. I can plot that. I'm going to plot that one, trplot2, parse in the matrix, there's going to be a frame, called 3 and I'm going to color that one green. So if I compound those 2 poses I end up with the pose shown here as 3. The way we can think about this is we moved from the world frame 2 from frame 1 which is rotated, and then in frame 1 we then moved 2 in the x direction and 1 in the y direction. But X and Y direction are frame 1, not on the world frame, and that gets us to the frame labeled as frame 3.

I could compound the poses in the opposite order. I'm going to create a new pose T4 and it's going to be pose 2 compounded with pose 1. We can see that's what the homogeneous transformation matrix looks like and it's different to T3. I can plot this. I can parse in T4. I can plot it as a frame labeled 4 and I'm going to plot it into color cyan. Here we can see the frame 4 which has resulted from compounding pose 2 with post 1. Now I'm going to introduce a point into the plot. I'm going to introduce a point at a coordinate 3, 2. I need to transpose that so that it becomes a column vector. There it is. I can plot that. Plot point P, and I'm going to plot is an asterisk. There we see it in our figure. If I want to determine the coordinate of the point with respect to frame 1 then what I need to do is to use the inverse of the relative pose 1, which is that, and multiply it by the points coordinate in homogeneous form. I'll take point P and I'm going to append a 1 to it. What I have now is the homogeneous coordinate of the asterisk with respect to the coordinate frame 1.

We learn how to describe the 2D pose of an object by a 3×3 homogeneous transformation matrix which has a special structure.

Try your hand at some online MATLAB problems. You’ll need to watch all the 2D “Spatial Maths” lessons to complete the problem set.

### Professor Peter Corke

Professor of Robotic Vision at QUT and Director of the Australian Centre for Robotic Vision (ACRV). Peter is also a Fellow of the IEEE, a senior Fellow of the Higher Education Academy, and on the editorial board of several robotics research journals.

### Skill level

This content assumes high school level mathematics and requires an understanding of undergraduate-level mathematics; for example, linear algebra - matrices, vectors, complex numbers, vector calculus and MATLAB programming.

Average

## Discussion

1. xikya says:

Hiya, at around 3:53 Peter starts talking about going from “Abstract to Real”. Can someone point me to some references so I can prove to myself that pose composition is equivalent to matrix multiplication? Or am I heading down a rabbit hole of 3 years of linear algebra by wanting to know this? I mean I can take it at face value if i have to but I would rather know WHY just for personal satisfaction. This video is overall very very good, information dense too, had to stop and pause it many times to understand what was being said.

1. xikya says:

Actually I think I may get WHY… the whole video was about WHY… I just have to multiply it out without matrices and with matrices and see if theyre equal

2. Shounak says:

Hello,
I seem to be getting some strange results in Matlab while using the SE2 function.

T1 = SE2(2 ,3 , 30, ‘deg’) returns a 3×3 matrix , but the size of this in Matlab is being shown as (1,1). I can invert it but can’t multiply a 3×1 vector to it. ! HELP.

1. Peter Corke says:

These videos were made using v9 of the Toolbox. v10 of the Toolbox has a few subtle differences, the result of the function you called is an object that contains a 3×3 matrix. You can get the actual matrix by T1.T or double(T).

>> T1 = SE2(2 ,3 , 30, 'deg') T1 = 0.8660 -0.5000 2 0.5000 0.8660 3 0 0 1 >> about T1 T1 [SE2] : 1x1 (72 bytes)

 >> T1b = SE2(2 ,3 , 30, 'deg').T T1b = 0.8660 -0.5000 2.0000 0.5000 0.8660 3.0000 0 0 1.0000 >> about T1b T1b [double] : 3x3 (72 bytes) % this is a proper MATLAB 3x3 matrix, and you can multiply it by a 3x1 vector >> T1b*[1 2 1]' ans = 1.8660 5.2321 1.0000 

% the object form allows us to directly transform a point using an overloaded multiplication operator >> T1*[1 2]' ans = 1.8660 5.2321

1. Shounak says:

Thank you, sir, for the clarification!

2. Ghofran AL-NABELSI says:

Thank you doctor for clarification I had the same issue when I was attending the course on Future Learn. But now I’ve got the answer. How could you be the best!

3. Krishna Chaitanya says:

Hello Professor,
I am getting the below mentioned errors every time I execute the commands mentioned in tutorial.
Matlab version R2019a
Undefined function or variable ‘SE2’.
Undefined function or variable ‘transl2’.

1. Peter Corke says:

Do you have the Robotics Toolbox installed? Which version?

4. Rohan says:

Good day sir,
The two Matlab examples reference frames ‘1’ and ‘2’ are defined with respect to axis([0 5 0 5]) and while defining reference frame ‘3’ as T3 = T1 * T2, can you please explain how this is a valid composition? I have this confusion because in previous lectures you have shown that for valid compose there are some rules that must be followed like 0T3 = 0T1 * 1T2 * 2T3, but here it’s kind of 0T3 = 0T1 * 0T2 only, please explain, how this is a valid compose or what exactly this T1 * T2 in case I have misunderstood it.

1. Peter Corke says:

Sorry for the delay, I’ve been on holiday… axis([0 5 0 5]) is not defining any kind of coordinate frame, it is the MATLAB command that sets the dimensions of the plot window, 0 to 5 in each of the x- and y-directions. All transformations like T1 and T2 can all be considered as (rigid body) motions. In the first instance I plot these motions relative to the origin. Then I show the resulting motion if they are compounded. This is just to give a visual idea about how composition works, and the fact that ordering is important. I am playing a bit loose with the “rules” as you have pointed out and in later examples/lessons I use the rules because they are so useful. In this lesson I’m just trying to give an understanding of the relationship between transformations, motions and coordinate frames – sorry if that has been confusing.

5. Ghofran AL-NABELSI says:

Thank you doctor
I would repost what the professor has clarified in a previous comment that you may replace the line :
p1=inv(T1.)*[p;1] at the end of the video by the line: p1=inv(T1.T)*[p;1] , In order to make the matrix multiplication valid for those who have Robotics Toolbox version 10.

6. Amer says:

thank you Professor,
There is some difference to the practical side in the video and what I found in the last toolbox, but everything is discussed in the comments.

1. Peter Corke says:

It would be great to update the videos, but for now I don’t have the resources to be able to do that. Sorry.