es

This section is divided into a number of subsections, links to which are:

Rotations

3D Rotations

Euler Theorem

Quaternions

Compositions

$Post := If[MatrixQ[#1], MatrixForm[#1], #1] & (* outputs matricies in MatrixForm*)
Remove[ "Global`*"] // Quiet (* remove all variables *)

 

2D Rotations

A 2D rotation about the origin has only one parameter, the angle, which defines the amount of rotation. The standard convention found in most math books is to consider counterclockwise rotation positive and clockwise rotation negative. We can do rotation about the origin using matrix multiplication. A rotation matrix is a transformation matrix that is used to perform a rotation of a plane by angle θ in counterclockwise direction.

We begin with rotating a point P(x₀, y₀) in the xy-plane about the origin through an angle θ in counterclockwise direction. We demonstrate derivation of the rotation matrix in two ways. First, we use trigonometric relations, and then show that the same matrix can be obtained based on rotations of basic vectors i = (1, 0) and j = (0, 1),

Suppose that a given point P(x₀, y₀) is moved under rotation by angle θ into a new point Q(x, y). In order to derive the rotation matrix, we recognize that the new point Q will be the same distance from the origin as the starting point P. So both points P and Q lie on the circle centered at the origin and radius r. The point Q is just an extra angle θ, as measured from the positive abscissa (= x-axis) relative to the position of P at this circle. If the point P is at angle ϕ, then the new point Q is at the angle ϕ + θ. Since all the points on the circle of radius r with center at the origin can be written as \( \displaystyle r\,e^{{\bf j}\alpha} = \left( r\,\cos\alpha , r\,\sin\alpha \right) \) for some real number α. We know that point P has coordinates \( \displaystyle r\,e^{{\bf j}\phi} = \left( r\,\cos\phi , r\,\sin\phi \right) , \) while point Q has coordinates \( \displaystyle r\,e^{{\bf j}(\phi + \theta )} = \left( r\,\cos (\phi + \theta ) , r\,\sin (\phi + \theta ) \right) , \) where j is the unit vector in the positive vertical direction on complex plane ℂ so j² = −1.

Rotation PQ
     
circle = Graphics[{Blue, Thickness[0.01], Circle[{0, 0}, 3]}]; p = {3 Cos[Pi/6], 3 Sin[Pi/6]}; q = {3 Cos[Pi/6 + 3*Pi/5], 3 Sin[Pi/6 + 3*Pi/5]}; arc = Graphics[{Red, Thickness[0.015], Circle[{0, 0}, 3, {Pi/6, Pi/6 + 3*Pi/5}]}]; angles = Graphics[{Black, Thick, Circle[{0, 0}, 1.7, {Pi/6, Pi/6 + 3*Pi/5}], Circle[{0, 0}, 0.9, {0, Pi/6}]}]; points = Graphics[{PointSize[0.05], Purple, Point[{p, q}]}]; lines = Graphics[{Black, Thickness[0.01], { Arrow[{{0, 0}, p}], Arrow[{{0, 0}, q}]}}]; txt = Graphics[ {Black, Text[Style["P", FontSize -> 18, Bold], {2.9, 1.9}], Text[Style["Q", FontSize -> 18, Bold], {-2.5, 2.3}], Text[Style["\[Theta]", FontSize -> 18, Bold], {-0.01, 0.5}], Text[Style["\[Phi]", FontSize -> 18, Bold], {1.1, 0.25}]}]; ll = Graphics[{Black, Thick, Arrow[{{0, 0}, {3.5, 0}}]} ]; txt2 = Graphics[ {Black, Text[Style["O", FontSize -> 18, Italic], {0, -0.4}], Text[Style["x", FontSize -> 18, Italic], {3.3, 0.3}]}]; Show[circle, arc, angles, points, lines, txt, ll, txt2]

Now we make an animation:
anim1 = Animate[ circle = Graphics[{Blue, Thickness[0.01], Circle[{0, 0}, 3]}]; p = {3 Cos[Pi/6], 3 Sin[Pi/6]}; q = {3 Cos[Pi/6 + increment*Pi/5], 3 Sin[Pi/6 + increment*Pi/5]}; points = Graphics[{PointSize[0.05], Purple, Point[{p, q}]}]; lines = Graphics[{Black, Thickness[0.01], {Arrow[{{0, 0}, p}], Arrow[{{0, 0}, q}]}}]; arc = Graphics[{Red, Thickness[0.015], Circle[{0, 0}, 3, {Pi/6, Pi/6 + increment*Pi/5}]}]; angles = Graphics[{Black, Thick, Circle[{0, 0}, 1.7, {Pi/6, Pi/6 + increment*Pi/5}], Circle[{0, 0}, 0.9, {0, Pi/6}]}]; ll = Graphics[{Green, Thick, Arrow[{{0, 0}, {3.5, 0}}]}]; txt = Graphics[{Black , Text[Style["P", FontSize -> 18, Bold], {2.9, 1.9}] , Text[Style["Q", FontSize -> 18, Bold], {-2.5, 2.3}] , If[increment > 1.54, Text[Style["\[Theta]", FontSize -> 18, Bold], {(*2 *) Cos[Pi/6 + increment/2 - 1*Pi/5],(*2 *) Sin[Pi/6 + increment/2 - 1*Pi/5]}]] , Text[Style["\[Phi]", FontSize -> 18, Bold], {1.1, 0.25}] , Text[Style["O", FontSize -> 18, Italic], {0, -0.4}] , Text[Style["x", Green, FontSize -> 18, Italic], {3.3, 0.3}]}]; Labeled[Show[circle, lines, arc, points, angles, ll, txt], "Rotation P\[RightArrow]Q"], {{increment, 0, "Added\nRadians"}, 0, 3, Appearance -> "Labeled"} , AnimationRepetitions -> Infinity , AnimationDirection -> ForwardBackward , Paneled -> False ]
Rotation PQ

In order to determine the rotation matrix, we express coordinates of point Q through coordinates of point P. To accomplish this task, we use trigonometric identities and delegate this job to Mathematica:

TrigExpand[Cos[a + b]]
Cos[a] Cos[b] - Sin[a] Sin[b]
TrigExpand[Sin[a + b]]
Cos[b] Sin[a] + Cos[a] Sin[b]
Then coordinates of point Q are expressed as
\begin{align*} Q &= \left( r\,\cos (\phi + \theta ), r\,\sin (\phi + \theta ) \right) \\ &= \left( r\,\cos\phi\, \cos\theta - r\,\sin\phi \,\sin\theta , r\,\sin\phi \,\cos\theta + r\,\cos\phi \,\sin\theta \right) \\ &= \left( \cos\theta\,x_0 - \sin\theta \,y_0 , \sin\theta \,x_0 + \cos\theta\, y_0 \right) . \end{align*}
Now we can express coordinates of point Q(x, y) through coordinates of point P(x₀, y₀)
\[ \left( x, y \right) = \left( \cos\theta\,x_0 - \sin\theta \,y_0 , \sin\theta \,x_0 + \cos\theta\, y_0 \right) \]
where x₀ = cos(ϕ) and y₀ = rsin(ϕ). If we convert coordinates of these two points from ℝ² into equivalent form as columns from ℝ2×1, we get
\[ \left[ \begin{array}{c} x \\ y \end{array} \right] = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} \cdot \left[ \begin{array}{c} x_0 \\ y_0 \end{array} \right] \]
Finally, we obtain 2×2 rotation matrix:
\begin{equation} \label{EqPlane.2} {\bf R} (\theta ) = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \phantom{-}\cos\theta \end{bmatrix} . \end{equation}

We can derive the rotation matrix \eqref{EqPlane.2} by considering transformation of base vectors i = (0, 1) and j = (0, 1).

Clear[p, q];
p = {1, 0};
q = {0, 1};
\[Theta] = 60 Degree
pPr = {Cos[\[Theta]], Sin[\[Theta]]};
qPr = {-Sin[\[Theta]], Cos[\[Theta]]} ;
Graphics[{Black, , Thick, Arrow[{{0, 0}, p}], Arrow[{{0, 0}, q}], Blue, Thick, Arrow[{{0, 0}, pPr}], Arrow[{{0, 0}, qPr}], Red, Thick, Arrow[Circle[{0, 0}, .25, {0, 60 Degree}]], Arrow[Circle[{0, 0}, .25, {Pi/2, 150 Degree}]], Text["i={1,0}", {.9, .05}], Text["j={0,1}", {-.11, .9}], Text["p={Cos(\[Theta]), Sin(\[Theta])}", pPr + .05], Text["q={-Sin(\[Theta]), Cos(\[Theta])}", qPr + .05], Text["\[Theta] = 60\[Degree]", {.35, .15}], Text["\[Theta] = 60\[Degree]", {-.15, .28}]}, Axes -> True, PlotLabel -> "Rotation in counterclockwise direction"]
Rotation coordinate vectors counterclockwise.
Clear[p, q];
p = {1, 0};
q = {0, 1};
\[Theta] = 60 Degree;
pPr = {Cos[\[Theta]], Sin[\[Theta]]};
qPr = {-Sin[\[Theta]], Cos[\[Theta]]};
Graphics[{Black, Thick, Arrow[{{0, 0}, p}] , Arrow[{{0, 0}, q}] , Blue, Thick, Arrow[{{0, 0}, pPr}] , Arrow[{{0, 0}, qPr}] , Red, Thick, Arrow[Circle[{0, 0}, .25, {0, 60 Degree}]] , Arrow[Circle[{0, 0}, .25, {Pi/2, 150 Degree}]] , Text["i={1,0}", {.9, .05}] , Text["j={0,1}", {-.11, .9}] , Text["p={Cos(\[Theta]), Sin(\[Theta])}", pPr + .05] , Text["q={-Sin(\[Theta]), Cos(\[Theta])}", qPr + .05] , Text["\[Theta] = 60°", {.35, .15}] , Text["\[Theta] = 60°", {-.15, .28}]} , Axes -> True , PlotLabel -> "Rotation in counterclockwise direction"]
Rotation coordinate vectors counterclockwise.
Moreover, rotation matrices are orthogonal matrices (A−1 = AT) with a determinant equals to 1.
rotat\[Theta] = house2[.5 {{Sqrt[3], -1}, {1, Sqrt[3]}}, "Rotation by angle \[Pi]/6"]; Grid[{{"House to be\nTransformed", "Transform\nMatrix", "Transformed\nHouse"}, {house[], HoldForm[1/2 MatrixForm[{{Sqrt[3] - 1}, {1, Sqrt[3]}}]], rotat\[Theta]}}, Frame -> All]

House in quadrant I.
      \[ \frac{1}{2} \begin{bmatrix} \sqrt{3} & -1 \\ 1 & \sqrt{3} \end{bmatrix} \]      
Rotation by angle π/6.

rotat\[Theta]2 = house2[.5 {{-Sqrt[3], -1}, {1, -Sqrt[3]}}, "Rotation by angle 5\[Pi]/6"]; Grid[{{"House to be\nTransformed", "Transform\nMatrix", "Transformed\nHouse"}, {house[], HoldForm[1/2 MatrixForm[{{-Sqrt[3] - 1}, {1, -Sqrt[3]}}]], rotat\[Theta]2}}, Frame -> All]

House in quadrant I.
      \[ \frac{1}{2} \begin{bmatrix} -\sqrt{3} & -1 \\ 1 & -\sqrt{3} \end{bmatrix} \]      
Rotation by angle 5π/6.

rotat\[Theta]3 = house2[(*.5*) {{0, -1}, {1, 0}}, "Rotation by 270\[Degree] clockwise"]; Grid[{{"House to be\nTransformed", "Transform\nMatrix", "Transformed\nHouse"}, {house[], HoldForm[(*1/2*) MatrixForm[{{0, -1}, {1, 0}}]], rotat\[Theta]3}}, Frame -> All]

House in quadrant I.
      \[ \frac{1}{2} \begin{bmatrix} 0 & -1 \\ 1 & \phantom{-}0 \end{bmatrix} \]      
Rotation by 270° clockwise.

rotat\[Theta]4 = house2[(*.5*) {{0, 1}, {-1, 0}}, "Rotation by 270\[Degree]\n counterclockwise"]; Grid[{{"House to be\nTransformed", "Transform\nMatrix", "Transformed\nHouse"}, {house[], HoldForm[(*1/2*) MatrixForm[{{0, 1}, {-1, 0}}]], rotat\[Theta]4}}, Frame -> All]

House in quadrant I.
      \[ \frac{1}{2} \begin{bmatrix} \phantom{-}0 & 1 \\ -1 & 0 \end{bmatrix} \]      
Rotation by 270° counterclockwise.

   
Example 1: Instead of rotating points, we consider the three padaled flower and rotate it with respect to a new center, not necesarily the origin.
(*Create ParametricPlot*)
F = (2*Cos[3*t] + 3)*Cos[t];
G = (2*Cos[3*t] + 3)*Sin[t];
origPlot = ParametricPlot[{F, G}, {t, 0, 2*Pi}, PlotStyle -> {Blue, Thickness[0.01]}]
Define Rotation Matrix R for counterclockwise rotation of 1.15 radians
R = {{Cos[a], -Sin[a]}, {Sin[a], Cos[a]}} /. a -> 1.15
Define Point P on original curve
P = {{F}, {G}};
Define point to serve as center of the rotation
center = {{-2}, {-3}};
Define new point Q obtained by rotating P counterclockwise by 1.15 radians about the center
Q = R . (P - center) + center;
Create a new ParametricPlot, now defined by Q and show the center \ with market "+"
rotPlot = ParametricPlot[Flatten[Q], {t, 0, 2*Pi}, PlotStyle -> {Purple, Thickness[0.01]}];
centerPlot = ListPlot[{Flatten[center]}, PlotMarkers -> {"+", Medium}];
sho2 = Show[rotPlot, centerPlot, PlotRange -> All]

Three pedal flower.
           
Rotation by 1.15 radians counterclockwise.

An alternative method

F = (2*Cos[3*t] + 3)*Cos[t];
G = (2*Cos[3*t] + 3)*Sin[t];
origPlot = ParametricPlot[{F, G}, {t, 0, 2*Pi}, PlotStyle -> {Blue, Thickness[0.01]}];
Use the built - in function to generate the rotation matrix
R = RotationMatrix[1.15];
P = {F, G}; center = {-2, -3}; Q = R . (P - center) + center; (* We don't need to flatten Q here *)
rotPlot2 = ParametricPlot[Q, {t, 0, 2*Pi}, PlotStyle -> {Purple, Thickness[0.01]}]; centerPlot2 = ListPlot[{center}, PlotMarkers -> {"+", Medium}]; sho3 = Show[rotPlot2, centerPlot2, PlotRange -> All]

The latter figure clearly depicts the rotation of the parametric curve. Now let us animate the rotation so all intermediate curves will be visible.

F = (2*Cos[3*t] + 2)*1*Cos[t];
G = (2*Cos[3*t] + 2)*1*Sin[t];
origPlot = ParametricPlot[{F, G}, {t, 0, 2*Pi}, PlotStyle -> {Blue, Thickness[0.01]}];
P = {{F}, {G}};
R = {{Cos[a], -Sin[a]}, {Sin[a], Cos[a]}};
center = {{-2}, {-3}};
QP = R.(P - center) + center;
centerPlot2 = Graphics[{Red, PointSize -> Medium, Point[{-2, -3}]}];
rotPlot = ParametricPlot[Flatten[Q], {t, 0, 2*Pi}, PlotStyle -> {Purple, Thickness[0.01]}]; anim2 = Animate[QPE = Evaluate[QP /. {a -> theta}]; QPEPlot = ParametricPlot[Flatten[QPE], {t, 0, 2*Pi}, PlotStyle -> {Black, Thickness[0.01]}]; Show[origPlot, QPEPlot, rotPlot, centerPlot2, PlotRange -> {{-10, 10}, {-10, 10}}], {{theta, 0, a}, 0, 2*Pi, Pi/16}, AnimationRepetitions -> Infinity ]
Animation of rotation
   ■
End of Example 1

  1. Consider the point P(2,1). Without using matrix multiplication, find the resulting point undr rotation about the origin by angles π/2 and π/4.
  2. Given a point P on the plane ℝ², let Q be the point corresponding to the rotation of P in counterclockwise direction about the origin through an angle θ. Let R be the point corresponding to the rotation of Q in counterclockwise direction about the origin through an angle ϕ. Verify that \[ \mathbf{R}[\phi ]\,\mathbf{R}[\theta ] = \mathbf{R}[\phi + \theta ] , \] where R[θ] is the rotation matrix according to formula (1). Does it mean that products of rotation matrices are commutative?
  3. Find the coordinates of the point Q corresponding to the point P(3, 2) that has been rotated in counterclockwise direction about the origin through an angle θ = 2π/3.

  1. Anton, Howard (2005), Elementary Linear Algebra (Applications Version) (9th ed.), Wiley International
  2. Dunn, F. and Parberry, I. (2002). 3D math primer for graphics and game development. Plano, Tex.: Wordware Pub.
  3. Foley, James D.; van Dam, Andries; Feiner, Steven K.; Hughes, John F. (1991), Computer Graphics: Principles and Practice (2nd ed.), Reading: Addison-Wesley, ISBN 0-201-12110-7
  4. Matrices and Linear Transformations
  5. Rogers, D.F., Adams, J. A., Mathematical Elements for Computer Graphics, McGraw-Hill Science/Engineering/Math, 1989.
  6. Watt, A., 3D Computer Graphics, Addison-Wesley; 3rd edition, 1999.