LESSON

# Describing rotation in 3D

#### Share

#### Transcript

For the two dimensional case we consider two coordinate frames, the original frame A, and a rotated version of that, coordinate frame B. And B is rotated in the positive direction by angle theta with respect to frame A. We then described the new coordinate frame axes in terms of the old coordinate frame axes, and we were able to write these relationships. We then wrote this in matrix form and we ended up with a formulation that allowed us to transform vectors from the new frame to the old frame A. The columns of this rotation matrix are the new X-axis that is the B-axis expressed in terms of the A coordinate frame and the BY-axis in terms of the A coordinate frame. We used some quite complex geometry and diagrams in order to show this.

For three dimensions it's a little complex to do that kind of geometric construction so we're just going to take the big principle from last time. We'll start off in a similar fashion, here's coordinate frame A and we've drawn a point which we can describe in terms of a vector with respect to coordinate frame A. I’m going to introduce a new coordinate frame B which is rotated with respect to coordinate frame A. And we're going to define the point with another vector, vector BP which is the point in respect to a rotated frame B. We're going to pull the same trick as we did for the 2-dimensional case. We're going to describe the axes of coordinate frame B as unit vectors expressed in terms of coordinate frame A and they are the columns of a new rotation matrix. In this case it's a 3x3 rotation matrix. So we're not going to go through the detailed geometric construction, we're going to extrapolate from the 2-dimensional case and just write this expression directly.

This new rotation matrix transforms vectors from the new coordinate frame B to the old coordinate frame A. This 3-dimensional rotation matrix, this 3x3 matrix, has got a lot of similar properties to it's 2x2 counterpart. It is an orthogonal, sometimes called orthonormal, matrix. That means each column in the matrix is a unit length vector. Each column in the matrix is orthogonal to all the other columns so that means if I take the dot product between column 1 and column 2 it will be equal to 0, same for column 1 and column 3, column 2 and column 3. The inverse of this matrix is the same as it's transpose and this is a really useful property because often times when we're computing pose expressions we need to find the inverse of the rotation matrix and computationally it's much simpler to compute the transpose than it is to compute the inverse for a 3x3 matrix. The determinant of this matrix is +1, that means when we multiply a vector by this matrix, its length will be unchanged. A Mathematician would say that a matrix like this belongs to the special orthogonal group of dimension 3 and that'll be written as R being an element of the set SO(3). Three indicating that the matrix is 3x3, it is rotation in 3-dimensional space.

There are some very useful rotation matrices that we can write down, we refer to these as elementary rotation matrices. The first one then is the rotation by theta around the X axis, rotation by theta around the Y axis and finally rotation by theta about the Z axis. And we can multiply these together in various combinations in order to achieve much more complicated rotations; more about that shortly. In the last lecture when we considered 2-dimensional rotations we wrote a rotation matrix that looks like this. In fact this is identical to the top left corner of the elementary rotation matrix for rotation about Z. The reason about this quite intuitive. In the 2 dimensional case we are actually rotating around the unseen Z axis which was sticking up at us out of the screen and was effectively invisible. So there is an equivalence between 2-dimensional rotation and the 3-dimensional rotation around the Z axis.

When we're talking about orientation we consider them in terms of a sequence of elementary rotations, so let's look at rotations around the X-axis. Now this was the positive rotation direction so if I rotate this coordinate frame by 90 degrees around the X-axis it's going to look like this. If I rotate it by minus 90 degrees around the X-axis it's going to look like this. I can rotate it by positive 90 degrees around the Y-axis so that's a rotation that way so positive 90 degrees rotation looks like this and a negative 90 degrees rotation is going to look like this. Now positive rotation around the Z-axis is this way, so if I rotate this frame 90 degrees around the Z-axis it's going to look like this or if I rotate it by minus 90 degrees around the Z-axis it's going to look like this.

Let's have a look at some of these elementary transformation matrices in MATLAB. We can use the function rotx to create a rotation about the X-axis and I'm going to ask for a rotation of 0.2 radians and this is what the rotation matrix looks like. I could have also specified the angle in terms of degrees so in this case what I look for is a rotation of 30 degrees around the X-axis.

Let me put that matrix into a variable which I'm going to call R for rotation it's a 3x3 orthogonal rotation matrix and we'll just test some of the properties we've mentioned earlier about orthogonal rotation matrices. I can look at the determinant of the matrix and we can see that it is equal to 1. I can compute the inverse of that matrix and we can see that it is exactly the same as a transpose of that matrix. And computationally this is particularly convenient instead of having to invert the matrix I can simply transpose it. Computationally much, much cheaper. I can also compute a rotation about a different axis I could ask for a rotation around the Y-axis by 0.2 radians or a rotation around the Z-axis, again by 0.3 radians. The toolbox also contains a function which allows me to graphically depict one of these rotation matrices as a rotated coordinate frame. So I can parse the last result, which is in the automatic variable ans into the function trplot and here we can see the representation of the rotated coordinate frame. The reference coordinate frame is indicated here and the rotated coordinate frame is shown here in blue. The trplot function has got many, many options. We can change the color of the coordinate frame, we can add a label to the frame, we can add arrowheads and so on.

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

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

Hi,

I am working on a 2DoF parallel manipulator driven by 3 linear actuators. The mechanism is constrained to allow pitch (about X, ψ) and roll (about Y, φ) only.

I used the rotation matrix in this lecture and it should be:

Rx = [1 0 0; 0 cosψ -sinψ; 0 sin ψ cos ψ]

Ry = [cosφ 0 sinφ; 0 1 0; -sinφ 0 cosφ]

R = Ry*Rx = [cosψ sinψsinφ cosψsinφ; 0 cosψ -sinψ; -sinφ cosφsinψ cosφcosψ]

Then I used this rotation matrix to calculate where the end position of each actuator should be in order to orient the end effector’s angle. However, this give me opposite direction in pitch. i.e.+3° resulted in -3°. (but roll was fine??!!) I altered the matrix to:

Rx = [1 0 0; 0 cosd(-ψ) -sind(-ψ); 0 sind(-ψ) cosd(-ψ)];

Ry = [cosd(φ) 0 -sind(φ); 0 1 0; sind(φ) 0 cosd(φ)];

Then I could now get the position of each actuator correctly to orient the end effector.

Although this is now working fine, I’d really appreciate if anyone can help to point out what did I do wrong here?

It’s hard to comment without a lot more detail. This manipulator is orientation only? End-effector has y-axis forward and x-axis to the left or right? Could the error be in your inverse kinematics rather than computing the desired orientation?

Sir in the newer versions of rtb toolbox the function rotx() only takes values in degrees and not in radians.

Not true. See the FAQ page

Thank you Dr. Corke using the Path Tool has helped me to solve the problem.

Sachin, I think the version of rotx() that is currently working is the one from MATLAB’s Phased Array toolbox and not the toolbox Peter is using.

You can check https://groups.google.com/forum/#!topic/robotics-tool-box/R-TgnkS-kMA for more details. To use rotx() from Peter’s toolbox, you can have the path of the toolbox precede the Phase Array toolbox.

Thank you for your help too

It is important to note that with new MATLAB versions you might feel you’ve got a 2D plot when you use the command trplot(), in fact all you have to do is to rotate the graph manually inside the Figure pop-up window to see all the three axis in 3D.

Good luck