Rotation
Contents
Rotation#
Rotation in \(\mathbb{R}^3\) is a linear transformation that rotates a set of points by some angle about one of the \(x\), \(y\) or \(z\)-axes. The direction of rotation is assumed to be anti-clockwise when viewed looking down the axis towards the origin (Fig. 37).
Consider the diagram in Fig. 38 that shows the axes from Fig. 37 when viewed looking down the \(x\)-axis. The point with position vector \(\mathbf{u}=(u_x, u_y, u_z)\) is rotated anti-clockwise about the \(x\)-axis by the angle \(\theta\) to \(\mathbf{v}=(v_x, v_y, v_z)\). To determine the linear transformation we first consider the rotation of a vector pointing along the \(x\)-axis which has the same magnitude of \(\mathbf{u}\), i.e., \(|\mathbf{u}| \mathbf{e}_1\), rotated by the angle \(\phi\). Forming a right-angled triangle with the angle \(\phi\) and hypotenuse of length \(|\mathbf{u}|\) then
Doing similar for rotating \(\mathbf{u}\) by the angle \(\theta\) to \(\mathbf{v}\) we have
using the angle sum indentities
then we have
Substituting equation (26) into equation (27)
which can be written as the matrix equation.
The square matrix is the transformation matrix for rotation by the angle \(\theta\) anti-clockwise about the \(z\)-axis, i.e., in Fig. 38 we are looking down the \(z\)-axis. Doing similar we can determine the equivalent matrices for rotating about the \(x\) and \(y\)-axes.
\(\mathbb{R}^3\))
(Rotation inThe rotation of a vector in \(\mathbb{R}^3\) expressed using homogeneous co-ordinates anti-clockwise by an angle \(\theta\) about the \(x\), \(y\) and \(z\) axes is the linear transformation given by the following rotation matrices.
Since \(\cos(-\theta) = \cos(\theta)\) and \(\sin(-\theta) = -\sin(\theta)\), the transformation matrices for inverse rotation, rotation in the clockwise direction, are
A triangular polygon has vertices located at \(\mathbf{p}_1 = (4, 1, 2)\), \(\mathbf{p}_2 = (6, 1, 2)\) and \(\mathbf{p}_3 = (5, 3, 2)\). The triangle is rotated by angle \(\theta = \pi/4\) anti-clockwise about the \(z\)-axis. Calculate the positions of the vertices of the rotated triangle.
Solution
The homogeneous co-ordinate matrix is
and the rotation matrix is
Applying the transformation
So the vertex co-ordinates fo the translated triangle are \((2.12, 3.54, 2)\), \((3.54, 4.95, 2)\) and \((1.41, 5.66, 2)\). The original triangle and the rotated triangle are plotted in Fig. 39 looking along the \(z\) axis.
MATLAB code#
The following MATLAB code applies the translation from Example 26 and plots the original and rotated polygons.
% Define homogeneous co-ordinate matrix
P = [ 4, 6, 5 ;
1, 1, 3 ;
2, 2, 2 ;
1, 1, 1 ];
% Define rotation matrix
Rz = @(theta) [ cos(theta), -sin(theta), 0, 0 ;
sin(theta), cos(theta), 0, 0 ;
0, 0, 1, 0 ;
0, 0, 0, 1 ];
% Apply rotation
theta = pi / 4;
P1 = Rz(theta) * P;
% Plot polygons
figure
patch(P(1,:), P(2,:), 'b', FaceAlpha=0.5)
patch(P1(1,:), P1(2,:), 'r', FaceAlpha=0.5)
axis equal
axis([0, 7, 0, 7])
xlabel("$x$", FontSize=12, Interpreter="latex")
ylabel("$y$", FontSize=12, Interpreter="latex")
box on
Rotation about polygon centre#
We saw in Example 26 that the polygon has shifted position because we rotate about the origin. If we wanted to rotate the polygon about its centre we first need to translate it so that its centre is at the origin, apply the rotation transformation and then translate the centre to the original position (Fig. 40).
If the centre of the polygon is at point \(\mathbf{c}=(c_x, c_y, c_z)\) then the first transformation is translation by \(-\mathbf{c}\) and the transformation matrix is
The second transformation is rotation around the origin using equation (28) and the third transformation is translation by \(\mathbf{c}\), so that the centre is back to the original position, using
The transformation matrix for the composite transformation that achieves rotation of a polygon about its centre is
where \(R(\theta)\) is either \(R_x(\theta)\), \(R_y(\theta)\) or \(R_z(\theta)\).
Rotate the polygon from Example 26 by \(\theta = \pi/4\) around the \(z\)-axis about its centre.
Solution
The homogeneous co-ordinate matrix is
and since the polygon is a triangle the co-ordinates of the centre are the average of the vertices
The individual transformation matrices are
which are multiplied to give the composite transformation matrix
Applying the composite transformation
So the vertices of the rotated polygon are \((4.76, 0.49, 2)\), \((6.18, 1.90, 2)\) and \((4.06, 2.61, 2)\). The original polygon and the rotated polygon are plotted below looking along the \(z\) axis.
MATLAB code#
The following MATLAB code applies the translation from Example 27 and plots the original and rotated polygons.
% Define homogeneous co-ordinate matrix
P = [ 4, 6, 5 ;
1, 1, 3 ;
2, 2, 2 ;
1, 1, 1 ];
% Calculate polygon centre
c = mean(P, 2);
% Define translation, scaling and rotation matrices
T = @(t) [ 1, 0, 0, t(1) ;
0, 1, 0, t(2) ;
0, 0, 1, t(3) ;
0, 0, 0, 1 ];
S = @(s) [ s(1), 0, 0, 0 ;
0, s(2), 0, 0 ;
0, 0, s(3), 0 ;
0, 0, 0, 1 ];
Rz = @(theta) [ cos(theta), -sin(theta), 0, 0 ;
sin(theta), cos(theta), 0, 0 ;
0, 0, 1, 0 ;
0, 0, 0, 1 ];
% Apply transformations
theta = pi/4;
P1 = T(c) * Rz(theta) * T(-c) * P;
% plot polygons
figure
patch(P(1,:), P(2,:), 'b', FaceAlpha=0.5)
patch(P1(1,:), P1(2,:), 'r', FaceAlpha=0.5)
axis equal
axis([0, 7, 0, 7])
xlabel("$x$", FontSize=12, Interpreter="latex")
ylabel("$z$", FontSize=12, Interpreter="latex")
box on
Rotation about a line#
Suppose we wish to rotate \(\mathbb{R}^3\) by an angle \(\theta\) about a general line that passes through the point \(\mathbf{p}=(p_x,p_y,p_z)\) with direction \(\mathbf{d}\) that does not pass through the origin and \(\mathbf{d}=(d_x,d_y,d_z)\) is not parallel to any of the three co-ordinate axes (Fig. 42). To achieve this we first need to apply translation and rotation so that the line lies along one of the co-ordinate axes, preform the rotation about this axis before reversing the rotation and translation operations. Each of the individual transformations can be represented by a matrix so the composite transformation that achieves the rotation about the line is a product of the individual matrices.
The first transformation is to translate by \(-\mathbf{p}\) so that the line passes through the origin so the transformation matrix is
Fig. 43 shows that affect of translating by \(-\mathbf{p}\). Now we need to rotate the line so that it lies in a plane the contains two of the three co-ordinate axes. The rotations required will depend on which of the eight directions \(\mathbf{d}\) is pointing in. In this case \(\mathbf{d}\) points towards the positive direction for all three axes, if we rotate about the \(z\) axis anti-clockwise by angle \(\phi\) then \(\mathbf{d}\) (and therefore the line) will be in the \(yz\) plane. The values of \(\cos(\phi)\) and \(\sin(\phi)\) in \(R_z(\phi)\) are
where \(d_1 = \sqrt{d_x^2 + d_y^2}\) is the hypotenuse of the right-angled triangle formed by projecting \(\mathbf{d}\) onto the \(xy\) plane. So the rotation matrix is
Fig. 44 shows that affect of rotating about the \(z\)-axis. Now we need to rotate clockwise about the \(x\) axis so that \(\mathbf{d}\) points along the \(z\) axis. The values of \(\cos(\psi)\) and \(\sin(\psi)\) are
so the transformation matrix is (note that the sign of the \(\sin(\psi)\) terms are switched because we are rotating in the clockwise direction)
Fig. 45 shows that affect of rotating about the \(x\)-axis. Now that the line is pointing along the \(z\)-axis we can perform the rotation about the line using \(R_z(\theta)\) and reverse the rotation in the \(x\) and \(z\) directions before finally reversing the translation. The composite transformation matrix is
A flight simulation program is simulating the flight of an aeroplane positioned with its centre of mass at \(\mathbf{c} = (10, 5, 50)\) travelling in the direction given by the vector \(\mathbf{d} = (2, -1, -3)\). The user performs a roll of the plane by rotating about \(\mathbf{d}\) by angle \(\theta = \pi/6\) in the anti-clockwise direction. Calculate the composite transformation matrix that performs this action.
Solution
First we translate by \(-\mathbf{c}\) so that the centre of the plane is at the origin.
Now we need to consider which rotations we apply so that \(\mathbf{d}\) points along one of the axes. This decision is arbitrary but in this case since \(d_x\) is positive then rotating so that \(\mathbf{d}\) points along the \(x\) axis would require the fewest rotations. Looking at Fig. 46 this means can first rotate anti-clockwise about the \(z\) axis by angle \(\phi\) so that \(\mathbf{d}\) is in the \(xz\) plane. The values of \(\cos(\phi)\) and \(\sin(\phi)\) are
and the transformation matrix is
We can check whether this rotation is correct by multiplying it by the homogeneous form of \(\mathbf{d}\)
Since \(d_y = 0\) then the rotated \(\mathbf{d}\) vector is now in the \(xz\) plane.
Looking at Fig. 46 we need to rotate clockwise around the \(y\) axis by angle \(\psi\) so that \(\mathbf{d}\) points along the \(x\) axis (remember that the direction of rotation is based on the view looking down the axis towards the origin). The values of \(\cos(\psi)\) and \(\sin(\psi)\) are
so the transformation matrix is
Again, we can check whether this rotation is correct by multiplying it by \(R_y(\psi) \cdot R_z(\phi) \cdot \mathbf{d}\)
Since \(d_y=0\), \(d_z=0\) and \(d_x > 0\) then \(\mathbf{d}\) is now pointing along the \(x\) axis.
Now we perform the rotation anti-clockwise around the \(x\) axis by angle \(\theta = \pi / 6\) and the matrix for achieving this rotation is
The rotations about the \(y\) and \(z\) axis and the translation are reversed so the complete composite matrix is
where