We have already seen how matrix multiplication can be used to translate and scale the vertices of an object. We will now look at the transfomation of rotation. It is possible to rotate an object in 2 or 3 dimensions using matrix multiplication. In 2D we can rotate about the origin or much like we did with scaling we can rotate about a center. The analogy in 3D is rotating about the 3 major axis or about an arbitrary axis..

# Rotations in 2D

First let us look at the two dimensional case. We will define the angle of rotation as $\phi$ measured counterclockwise from the positive *x*-axis in the usual fashion.

## Rotation about the Origin

The image below shows a rotation of an angle of $\phi$ about the origin.

The resulting vector can be rewritten using the trigonometric identities

(1)The resulting vector then becomes

(2)So, to rotate about the origin counterclockwise by an angle of $\phi$ in homogenous coordinates we would multiply on the left by the following.

(3)For clockwise rotation, the angle would be negative.

Below is an interactive demonstration that aloows you to adjust the point to be rotated and the angle of rotation along with the corresponding matrix operation.

## Rotation about a Center

To rotate about a center, we do much the same thing we did with scaling about a center. First, translate the center to the origin. Second rotate about the origin. Third translate back. So in 2D, to rotate by an angle of $\phi$, about the center point $(x_c,y_c)$, we would do the following.

(4)# Rotations in 3D

In three dimensions we rotate about an axis instead of a point. The axis of rotation can be one of the major axes or an arbitrary line in space.

## Rotation about the Major Axes

From the 2D rotation about the origin it is possible to derive matrices for the 3D rotations about the *x*, *y* and *z* axes. This is due to the fact that when rotating about one of the major axes, the *x*-axis say, the corresponding coordinate, *x*, stays fixed. In other words, rotation about the *x*-axis in 3D is really a 2D rotation in a plane parallel to the *yz*-plane.

In 3D, the concepts of clockwise and counter-clockwise are ambiguous, so we will rotate by the right hand rule. For example, a positive angle of rotation about the *x*-axis is determined by the direction the fingers of your right hand curl when your thumb points in the direction of the positive *x*-axis.

### Rotation about the x-axis

In order to rotate a 3D vector about the *x*-axis, according to the right-hand rule, we will multiply our vector on the left by the matrix,

### Rotation about the y-axis

In order to rotate a 3D vector about the *y*-axis, according to the right-hand rule, we will multiply our vector on the left by the matrix,

### Rotation about the z-axis

In order to rotate a 3D vector about the *z*-axis, according to the right-hand rule, we will multiply our vector on the left by the matrix,

Notice that the third row and column are from the multiplicative identity matrix and therefore leave the *z* coordinate unchanged. Also, if we remove the third row and column we get the matrix for 2D rotation about the origin. This is because as you rotate about the z-axis, you are staying in a plane parallel to the *xy*-plane.

## Rotation about an Arbitrary Axis in 3D

We will now look at rotating in 3D about an axis that is defined parametrically. The idea is to perform the transformations that would bring the line into agreement with one of the major axes and then rotate about that axis and then reverse the transformations.

Say we want to rotate an angle of $\phi$about the axis defined by the line

First, we will translate the line so it passes through the origin. We know the line passes through $(x_0,y_0,z_0)$, so if we translate in the direction $\vec{d}=<-x_0,-y_0,-z_0>$, the line will now pass through the origin. So our first step is to apply the matrix

(9)Now we will rotate this new axis about the *z*-axis, until it lies in the *yz*-plane with $y \geq 0$. Since our last transformation was only a translation, our current axis still has direction $\vec{v}=<v_x,v_y,v_z>$. To determine the angle we need to rotate, we need to find the angle between $\vec{v}$ and the positive *yz*-plane. This is equivalent to finding the angle between the projection of $\vec{v}$ into the *xy*-plane and the vector $\vec{j}=<0,1,0>$. Let us call the projection of $\vec{v}$ into the *xy*-plane $\vec{w}$.

This angle of rotation is simply the Direction angle $\beta$. We do need to be careful about the orientation of our vector though. In the image above our vector is in the first quadrant, but the picture changes in the other quadrants.

As you can see by the image above, for $v_x \geq 0$ we rotate by $\beta$, but for $v_x<0$ we rotate by $-\beta$.

Now we need to know the angle required to rotate our vector about the *x*-axis up to the positive *z*-axis. Since our last rotation was about the *z*-axis, the angle up to the positive *z*-axis did not change with the rotation. The angle would simply be the angle between $\vec{v}$ and $k=<0,0,1>$, which is our Direction angle $\gamma$.

.

Now that we are aligned with the positive *z*-axis, we will rotate about the *z*-axis by our original angle of $\phi$. To return the axis back to its original location we undo the preceding steps. In total we would have the following:

- Translate $\vec{d}$
- Rotate about the
*z*-axis by the angle $\beta$ ( or $-\beta$ ) - Rotate about the
*x*-axis by the anlge $\gamma$ - Rotate about the
*z*-axis by the angle $\theta$ - Rotate about the
*x*-axis by the anlge $-\gamma$ - Rotate about the
*z*-axis by the angle $-\beta$ ( or $\beta$ ) - Translate $-\vec{d}$

# Exercises

1) When we are using our 2D rotation matrix, with $\theta>0$, what direction is the rotation.

2) When we are using our 3D matrices for rotation about the major axes, with $\theta > 0$, what is the direction of rotation?

3) Rotate the 2D point (3, 5) clockwise 70° about the origin.

4) Rotate the 3D point (4, –2, 6) about the y-axis $50^{\circ}$ .

5) Rotate the 2D point (-2,-2) counter-clockwise $200^{\circ}$ about the point (2,2)

6) Give the concatenation for 2D counter-clockwise rotation of an angle $\theta$ about a center $(x_c,y_c)$

On exercises 7 and 8 just list the transformations needed in the following manner

Step 1) Translate $\vec{d}$

Step 2) Rotate about thez-axis by the angle $\beta$ ( or $-\beta$ )

Step 3) Rotate about thex-axis by the anlge $\gamma$

Step 4) Rotate about thez-axis by the angle $\theta$

Step 5) Rotate about thex-axis by the anlge $-\gamma$

Step 6) Rotate about thez-axis by the angle $-\beta$ ( or $\beta$ )

Step 7) Translate $-\vec{d}$

7) Give all the transformations in order that would be needed to rotate a point $30^{\circ}$ about the line passing through $P(1,-1,2)$ and in the direction of $\vec{v}= \left < 2,1,-1 \right >$

8) Give all the transformations in order that would be needed to rotate a point $45^{\circ}$ about the line passing through $P(1,2,3)$ and in the direction of $\vec{v}= \left < 0,0,1 \right >$

about the line defined by,