LESSON

# Describing rotation in 2D

#### Share

#### Transcript

This should be very familiar to us by now: a coordinate frame labeled A and a single point. We can describe the point by a vector with respect to frame A. The leading A in front of the P indicates that. I can write this vector in terms of its components - its distances along the XA axis and the YA axis and the unit vectors XA and YA hat. Now, let’s introduce a new coordinate frame, frame B, and it has got the same origin that’s rotated by the angle Theta. I can describe the point by a vector with respect to coordinate frame B and I can write that in terms of the unit vectors XB and YB hat and they’re indicated here in red. I can write expressions for XB hat in terms of cos Theta and sine Theta, and I can write an expression for YB hat in terms of minus sine Theta and cos Theta. If I substitute these two equations into here, I can write this expression. Then I can expand, rearrange and factor out XA hat and YA hat. The next thing to observe is because these two coordinate frames share an origin, then the vector AP and BP are in fact exactly the same. The coefficients of XA hat must be the same, so we can write this. And, the coefficients of YA hat must be the same, so we can write this. Let’s take those two expressions. Simplify things a little bit and we can now write this in matrix form. If you’re a little unsure about this step, then just multiply it out and you’ll find that you get the expressions above. Now, we write the vector part more concisely. Instead of in terms of its individual elements, we write it as the symbol P with respect to a particular coordinate frame. So, this expression relates the vector with respect to frame B to the vector with respect to frame A. It is achieved by multiplying the components of vector B by this 2 x 2 matrix.

We can make the expression even more concise and write it like this. And, we introduce the symbol R to represent a rotation matrix. This is a very concise way of representing the relationship between two vectors in different coordinate frames, and they are related by a rotation matrix R. Here we have the same expression as before, and to be a bit more precise, a bit more careful, we will add some labels to the matrix R and we will put a leading A and a trailing B. And, this indicates that R is a rotation matrix that rotates a vector from frame B to frame A. It’s important to note and not be confused by this: the matrix R depends on the rotation angle from frame A to frame B. The order of these two things is different and don’t get tripped up by that.

Let’s have a look at the rotation matrix. A matrix like this is referred to as an orthogonal matrix or sometimes an orthonormal matrix. Each column in this matrix is a unit vector and you can show that for yourself pretty easily. Each column in the matrix is orthogonal to the other columns. In this case, there are only two columns and you can show, again very easily, that a vector formed by the first column is orthogonal to the vector formed by the second column. The dot product of the two columns will be equal to zero. A really useful property of an orthogonal matrix is that its inverse is the same as its transpose. Computing the inverse of a matrix is rather complex, whereas computing its transpose is really very simple. So, it’s great that we have a matrix whose inverse can be computed very simply by transposing the elements of the matrix.

Another property of the rotation matrix is that its determinant is always equal to 1. And this means that, if I multiply any vector by this matrix, the length of the vector is unchanged. That’s an important property of a rotation matrix. When I rotate a vector from one coordinate frame to another, its length is not changed. A mathematician would say that a rotation matrix like this belongs to the special orthogonal group of dimension two. And, symbolically, we’d write that as R is an element of - belongs to - the set SO(2), special orthogonal group of dimension 2. Here’s the expression from above. And, if I take the rotation matrix across the other side of the equal sign, I can write this. This indicates that if I want to rotate a vector from coordinate frame A into coordinate frame B, I use the inverse of the rotation matrix from coordinate frame A to coordinate frame B. And, remember, that the inverse of a rotation matrix is simply its transpose.

The labels A and B in this first expression are completely general and it’s completely proper for me to swap the A and the B and now I can write this. These two equations are equivalent. So, now I can write this and this is really important. What it says is the rotation matrix from coordinate frame B to coordinate frame A is the inverse of the rotation matrix from coordinate frame A to coordinate frame B. Let’s have a look at some concrete examples of this in MATLAB. First of all, I’m going to create a two-dimensional rotation matrix using the Toolbox command rot2 for rotation matrix in two dimensions. And, I’m going to ask for a rotation angle of 0 radians. And, here is the 2 by 2 rotation matrix and it is the identity matrix. It’s got 1s on the diagonal and 0s on the off diagonal.

I can ask for a rotation that corresponds to an angle say of nought point 2 radians and this is that rotation matrix. I can also specify the angle in degrees. So, for instance, I could ask for the angle R of 30 degrees and this is the corresponding rotation matrix. What I’m going to do is to put that result in to the workspace variable R and here is the rotation matrix again for a rotation of positive 30 degrees. Now, we talked a moment ago about this rotation matrix having a number of properties, and one of the properties was that the columns are orthogonal. So, I’m going to create a variable which represents the first column of a matrix, another variable which corresponds to the second column of the matrix. And, if I look at the dot product of those two vectors, we can see that it is equal to 0. Another property that we mentioned is that the determinant of the matrix is equal to positive 1 and we can quite easily verify that. Another property we talked about is that the inverse of the matrix is the same as its transpose. So, the inverse of the matrix is computed using the MATLAB built in function inv, and the transpose is computed using the quote operator just like that and we can see quite clearly that the inverse is equal to the transpose.

Finally, we can visualize this rotation matrix as a rotated coordinate frame. To do that, I use the Toolbox function, trplot2. It’s a short for transform plot in two dimensions. I pass in the rotation matrix that I’m interested in and there is a representation of the coordinate frame. Now, it looks a little bit odd because I need to set the axis scaling to equal and here we see a right angled coordinate frame shown here in blue and we can see that it is rotated with respect to the world coordinate frame.

#### Code

We learn how to describe the orientation of an object by a 2×2 rotation matrix which has some special properties.

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

### Skill level

Undergraduate mathematics

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.

### Rate this lesson

## Check your understanding

## Discussion

## Leave a comment

Please Sign In to leave a comment.

Awesome!

Absolutely awesome series of videos, really high quality and much appreciated, thank you! I have a question about the aRb matrix notation (imagine the a is raised and b is lowered, hard to do it here in text). At around 5:02 in the video Prof Corke states that to rotate a vector from frame {A} to frame {B} we use the inverse rotation matrix from frame {A} to frame {B}. Shouldnt he have said “inverse rotation matrix from frame {B} to frame {A}”? My understanding is that the notation aRb rotates a vector from frame {B} to frame {A}.

Hi. You are indeed correct here. I believe Peter simply misspoke in this instance, an easy thing to do when delivering such content. I will update this in the transcript however getting the video updated may take some time. Thank you for reporting this.

James

Thanks James, yeah I thought that may be the case as he paused slightly before saying it.

I was confused at that instant as well!

Forgive the question, but I’m struggling to understand how we derived those particular values for Y-hat of Bp. Is there a video that anyone could link me to that can help me better understand this? It’s a current roadblock of mine. Thanks!

Can you give me the timecode for where you get stuck and I’ll talk you through it. In retrospect a much simpler approach is to use polar coordinates, see https://en.wikipedia.org/wiki/Rotation_of_axes

Hey! Right around 1:02! Why is sin suddenly negative? Also, why is sin along what had previously been the x-axis? I know it must be because of where we’re taking theta from but where exactly is that now? I’m guessing there is something fundamental i’m missing…?

ah ha! Just realized what I wasn’t understanding. I should really have been looking upon this coordinate frame as if from above, right? That way when our frame rotates, it is in fact rotating into a negative region-therefore sin is negative. Is this the correct way to visualize/think about this?

Correct. Not sure what you mean by “negative region” but positive rotation is defined as being counter clockwise. The reason is that the z-axis is upward (for a right-handed frame) and the right-hand rule gives positive rotation about that upward z-axis as counter clockwise.

Another way to look at it is the theta angle between X-hat of A and X-hat of B is equivalent to the angle between Y-hat of A and Y-hat of B. Therefore; the -sin theta

What about more exotic orientations? What if you were to flip it so that the y-axis was pointing down, x-axis stayed the same, and then wanted to measure theta from the y-axis? Like you might find in a robot mounted from the ceiling.

What changes about the rotation matrices?

You could do these things and compute how the rotation matrices differ, at the very least it would have a determinant of -1. But this is a dangerous road to go down and I would strongly advise that you stick with right-handed coordinate frames.

That would be possible but with 3D geometry. It would be a Roll rotation of 180 degrees.

Hello.

What matlab toolbox is that one? I don´t have it in mine.

Thank you

Regards

Jonathan

See the resources button at the top. These are my own free robotics and vision toolboxes that have existed for much longer than the official MathWorks ones. Get them from http://petercorke.com/toolboxes

sir i am unable to use your toolbox there are thousand’s of files and how to double click every one it so much time consuming,is there any other way sir

I GOT ANSWER from below link https://www.mathworks.com/help/matlab/ref/matlab.addons.toolbox.installtoolbox.html#bu581_0-2

toolboxFile = ‘C:\Downloads\MyToolbox.mltbx’;

agreeToLicense = true;

installedToolbox = matlab.addons.toolbox.installToolbox(toolboxFile,agreeToLicense)

location can vary with where we have keep file go to properties to check location

Canyon explain your problem more clearly. Did you follow the Toolbox install instructions on my website?

how can I find these slides which the prof explains these lessons