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.
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.
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.