Rotations Learning Objectives

Extend your vector class ( or your matrix class ) to perform multiplication by a matrix that will rotate an object.

Introduction

In experiment 7, you extended your vector class to include scaling and translations of objects using matrix multiplication. One additional operation is necessary to model basic motion, and that is rotation. A simple rotation by an angle θ in 2D involves the multiplication by the matrix

(1)
\begin{align} R_o= \left[ \begin{array}{cc} \cos \theta & -\sin\theta \\ \sin \theta & \cos \theta \\ \end{array} \right] \end{align}

In the 3D world, a basic rotation is a rotation about one of the three coordinate axes. Therefore, there are three basic rotation matrices. In homogeneous coordinates, these matrices are:

(2)
\begin{align} R_x= \left[ \begin{array}{cccc} 1 & 0 & 0 & 0\\ 0 & \cos \theta & -\sin\theta & 0\\ 0 & \sin \theta & \cos \theta & 0\\ 0 & 0 & 0 & 1\\ \end{array} \right] R_y= \left[ \begin{array}{cccc} \cos \theta & 0 & \sin\theta & 0\\ 0 & 1 & 0 & 0\\ -\sin \theta & 0 & \cos \theta & 0\\ 0 & 0 & 0 & 1\\ \end{array} \right] R_z= \left[ \begin{array}{cccc} \cos \theta & -\sin\theta & 0 & 0\\ \sin \theta & \cos \theta & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1\\ \end{array} \right] \end{align}

Since you already have written scaling and translation matrices in a previous experiment, you should be able to copy that function code, then make a few modifications to it to handle rotations. The major differences found in rotations, but not in scaling and translations, are the three axis-dependent cases, the use of trig functions (which necessitates degree/radian conversion considerations), and a single input parameter that describes the angle.

The three basic rotation matrices always use one of the coordinate axes as the axis of rotation. Three other cases are possible, depending on whether the axis of rotation passes through the origin or not, and whether the axis of rotation is parallel to the coordinate axes or not. The post-lab questions will explore this issue.

Since the goal of this lab is almost identical to the goal of the scaling lab, you may reuse and modify the main( ) function from that lab. You may also reuse the same 3D object you created for that experiment, or create another.

Prelab Questions and Exercises

1. Design your own 3D object and give the coordinates of its vertices using homogeneous coordinates at a location away from the origin. (You may reuse the object you created in experiment 7, or create a new object. In either case, give the coordinates.)
2. Set up the 4D matrix multiplication that would perform a rotation of your 3D object 30 degrees about the z-axis. Then do the multiplication on your object and obtain the new coordinates. (You may do the multiplication on a calculator.)
3. Set up the 4D matrix multiplication that would perform a rotation of your 3D object 50 degrees about the x-axis. Then do the multiplication on your object and obtain the new coordinates.
4. Set up the 4D matrix multiplication that would perform a rotation of your 3D object 130 degrees about the y-axis. Then do the multiplication on your object and obtain the new coordinates.

Laboratory Procedures

1. Extend your 3D vector class to include the following new methods:

• multiplication by a matrix that rotates about the x-axis
• multiplication by a matrix that rotates about the y-axis
• multiplication by a matrix that rotates about the z-axis

2. Create a C++ program that transforms the object you chose in prelab question #1. Specifically, the program should:

• report the object’s position
• ask the user to enter the type of transformation (translation, scaling, or rotation)
• ask the user for the needed parameters for that type of transformation (for rotations, the size of the angle and the axis of rotation are needed)
• perform the transformation
• repeat the above steps

[Note that these are essentially the same steps requested in experiment 7.]

3. Test your code using the questions from the pre-lab, and your pre-lab results.

4. Execute the above program, for your instructor’s verification.
Initials: x-axis: _ y-axis: _ z-axis: _

5. Save your class files! We will use them again in the rotational motion lab.

Postlab Questions

1. The 3D rotation functions about the coordinate axes can be used to rotate a 2D object about the origin in a 2D world. Explain how.
2. Suppose a 3D object has an axis of rotation that does not pass through the origin but is parallel to the z-axis. Explain how to do this rotation using only basic transformations.
3. Suppose a 3D object has an axis of rotation that does not pass through the origin and is not parallel to the z-axis. Explain how to do this rotation using only basic transformations.
page revision: 18, last edited: 20 Nov 2017 20:48