Homework #1 Solutions

Definitions

Off[General::spell1];
Off[General::spell];

Definition of elementary rotation matrices

RX[
          a_] := {{1, 0, 0}, {0,  Cos[a],  -Sin[a]}, {0, Sin[a],  
            Cos[a]}};
RY[
          a_] := {{Cos[a], 0, Sin[a]}, {0, 1, 0},  {-Sin[a], 0, 
            Cos[a]}};
RZ[
          a_] := {{Cos[a],  -Sin[a], 0}, {Sin[a], Cos[a], 0}, {0, 0, 
            1}};

Problem 1:

Part (a)

Since the second rotation is with respect to the moving frame {B}, we post-multiply, rather than premultiply successive rotations.

aRb  =  
      RZ[θ] . 
        RX[ϕ];  aRb // TraditionalForm

Part (b)

Since the rotation is now with respect to the fixed frame {A}, we pre-multiply successive rotations.

aRb  =  RX[ϕ] . RZ[θ];  
    aRb  //  TraditionalForm

Problem 2:

See solutions text.

Probelm 3:

Definition of Rk(θ)

\(\(RK[θ_] := \ {
		{kx^2\ \((1 - Cos[θ])\)\  + \ 
              Cos[θ], 
			kx\ ky\ \((1 - \ Cos[θ])\)\  - \ 
              kz\ Sin[θ], 
			kx\ kz\ \((1\  - 
                    Cos[θ])\)\  + \ 
              ky\ Sin[θ]}, 
		{kx\ ky\ \((1 - \ 
                    Cos[θ])\)\  + \ 
              kz\ Sin[θ], 
			ky^2\ \((1 - Cos[θ])\) + 
              Cos[θ], 
			ky\ kz\ \((1 - Cos[θ])\) - 
              kx\ Sin[θ]}, 
		{kx\ kz\ \((1 - Cos[θ])\) - 
              ky\ Sin[θ], 
			ky\ kz\ \((1 - Cos[θ])\) + 
              kx\ Sin[θ], 
			kz^2\ \((1 - Cos[θ])\) + 
              Cos[θ]}};\)\)

Solution

To prove eq. (2) of the homework, we can differentiate Rk(θ) with respect to θ two different ways: (1) element by element, and (2) by applying eq. (5) of the homework. If the two results are equivalent, than eq. (2) must be true.

κ  = {{0,  -kz,  ky}, {kz,  0,  -kx}, {-ky,  
            kx,  0}};

result1 = D[RK[θ],  θ]  //  FullSimplify;  
    result1  //  TraditionalForm

result2 = κ . 
        RK[θ];  TraditionalForm /@ result2

The two results certainly don't look the same. Let's try to simplify the above result...

result2  =  result2  //  FullSimplify;  
    result2  //  TraditionalForm

Now, all but the diagonal terms of the two equations are identical. However, since k is a unit vector, kx^2 + ky^2 + kz^2 = 1. Let's make some substitutions:

result2  = 
      result2  /.  {(ky^2  +  kz^2)  ->  (1 - 
                kx^2),  (kx^2  +  kz^2)  ->  (1 - 
                ky^2),  (kx^2  +  ky^2)  ->  (1 - kz^2)}; 
    result2  = result2  //  FullSimplify;  
    result2  //  TraditionalForm

Finally, we can test if the two results are the same:

result1  ==  result2

Problem 4

See solutions text.

Problem 5

Homogeneous transform

\(T[r_, \ p_] := 
	
      Join[Join[Transpose[r], \ {p}]\  // \ 
          Transpose, {{0, 0, 0, 1}}]\)

\(\(Tinv[r_, p_] := 
	
        T[Transpose[r], \ \(-Transpose[r] . p\)];\)\)

Part (a)

aRb  =  RZ[Pi]; 
aPborg  =  {3, 0, 0}; 
aTb  =  T[aRb,  aPborg]; 
aTb //  TraditionalForm

Part (b)

bRc  =  RY[Pi/2] . RX[Pi/2  +  Pi/3]; 
bRc  //  TraditionalForm

aPcorg  =  {3, 0, 2}; 
aTc  =  T[aRb . bRc,  aPcorg]; 
aTc  //  TraditionalForm

Part (c)

bRc  =  RY[Pi] . RX[-Pi/2] . RZ[-Pi/6]; 
bPcorg  =  {3, 0, 0};  bTc  =  T[bRc,  bPcorg];
bTc  //  TraditionalForm

Part (d)

aRb  =  RZ[Pi] . RX[-Pi/2]; 
aRb  // TraditionalForm

aRc  =  aRb . bRc; 
aPcorg  =  {-3, 3  Sqrt[3], 2};
aTc  =  T[aRc,  aPcorg]; 
aTc  //  TraditionalForm

cTa  =  Tinv[aRc,  aPcorg];
cTa  //  TraditionalForm

Problem 6

Quaternion package

<< Algebra`Quaternions`

norm[v_] := Sqrt[v . v];

\(\(equivAngleAxis[q_] := 
	
        Module[{ql, s, v}, 
		ql = \ List\  @@ \ q; 
		s\  = \ 
            ql[\([1]\)]; 
		v\  = \ 
            Drop[ql, 1]; 
		{2\ ArcTan[\ s, norm[v]], \ 
            v/norm[v]}];\)\)

Definition of distance metric

e[q_,  p_] := 
        Sqrt[((List  @@  q)  -  (List  @@  
                    p)) . ((List  @@  q)  -  (List  @@  
                    p))];

d[q_, p_] := Min[e[q, p], e[q, -p]];

Part (a)

See solutions text.

Part (b)

See solutions text.

Part (c)

Here are the quaternions:

q  =  Quaternion[(1/(Sqrt[2])), 0, (1/(Sqrt[2])), 0];
qp  =  
        Quaternion[(1/4) (-1 + (Sqrt[6])), 0, (1/4) (1 + (Sqrt[6])), 
          (1/(2 (Sqrt[2])))];
qpp  = 
        Quaternion[(1/32) (-6 + 9 (Sqrt[2]) - 4 (Sqrt[3]) - (Sqrt[6])), 
          (1/16) (-2 + (Sqrt[3]) - (Sqrt[6])), 
          (1/32) (6 + 11 (Sqrt[2]) + 4 (Sqrt[3]) - (Sqrt[6])), 
          (1/16) (-1 + 4 (Sqrt[6]))];

Let's just verify that they are unit quaternions:

Abs[q]

Abs[qp]  //  Simplify

Abs[qpp]  //  Simplify

Now let's compute the distances:

d1  =  d[q, qp]  //  Simplify

d1  //  N

d2  =  d[qp,  qpp]  //  Simplify

d2  //  N

d3  =  d[q,  qpp]  //  Simplify

d3  //  N

Now, let's verify that these numbers obey the triangle inequality:

d[q, qp]  +  d[qp,  qpp]  >=  d[q,  qpp]

d[qp,  qpp]  +  d[qpp,  q]  >=  d[qp,  q]

d[qp,  q]  +  d[q,  qpp]  >=  d[qp,  qpp]

Part (d)

r1  =  (qp^-1) ** q  //  FullSimplify

r1  //  N

{θ1,  k1} = equivAngleAxis[r1]

{θ1, k1}  //  N

r2  =  (qpp^-1) ** qp  //  FullSimplify

r2  //  N

{θ2,  k2} = equivAngleAxis[r2]  //  FullSimplify

{θ2, k2}  //  N

r3  =  (qpp^-1) ** q  //  FullSimplify

r3  //  N

{θ3,  k3} = equivAngleAxis[r3]  //  FullSimplify

{θ3, k3}  //  N

Note that the distance measure seems to be correlated to the angle of rotation between two quaternions. From q to qp, and qp to qpp, the rotation angle between them is the same (π/3), as is the distance measure. The rotation angle between q and qpp is almost twice as large as between q and qp, as is the distance measure. Therefore, the distance measure appears to be strongly related to the angle of rotation between two quaternions.

Part (e)

Let us assign the following three quaternions q, p and u. We will proceed by first showing that the distance measure between u (the zero-rotation unit quaternion) and an arbitrary quaternion p depends only on the rotation angle θ. We will then generalize this result by rotating both p and u by an arbitrary quaternion q, and showing that the distance measure remains the same.

q  =  Quaternion[s, x, y, z]

θ =. ; 
    p  =  Quaternion[Cos[θ/2],  Sin[θ/2] kx,  
        Sin[θ/2] ky, Sin[θ/2] kz]

u  =  Quaternion[1, 0, 0, 0]

res1  =  d[u,  p]  //  FullSimplify

res1a = ExpandAll[(res1  /.  {(kx^2  +  
                    ky^2  +  kz^2)  ->  1})]

res1a  =  
      res1a  /.  {Cos[(θ/2)]^2  +  Sin[(θ/2)]^2  ->  
            1}

res1b  =  res1a  //  FullSimplify

Plot[res1b, {θ, 0, 2  Pi}];

The two results (res1a and res1b)  above give  two  equivalent expressions for  d(u, p). The graph above plots this for θ ranging from 0 to 2π. Note that the distance measure reaches a peak at θ=π. What remains is to show that this result does not change if we multiply both u and p by an arbitrary unit quaternion q.

p1  =  q ** p

p2  =  q ** u

res2  =  d[p1, p2]

res2  =  res2  //  FullSimplify

res2  =  
      res2  /.  (s^2  +  x^2  +  y^2  +  z^2)  ->  1

res2  =  
      res2  //.  (kx^2  +  ky^2  +  kz^2)  ->  1

res2  =  res2  //  FullSimplify

Note that this result is, as expected identical, to the previous result and shows that the distance measure is dependent only on the angle of rotation θ between two unit quaternions.

Part (f)

We will use the result from part (e) to illustrate the triangle inequality. Consider three unit quaternions q, q' and q''. Let q and q' be separated by an angle of rotation θ1, and let q' and q'' be separated by an angle of rotation θ2. Also define d(θ) = distance measure for two unit quaternions separated by an angle of rotation θ. Then, all that needs to be shown is that d(θ1) + d(θ2) >= d(θ1 + θ2) for all θ1, θ2, or alternatively that f(θ1, θ2) = d(θ1) + d(θ2) - d(θ1 + θ2) >= 0. This is most easily shown graphically.

d[θ_] := 
        Min[2 Abs[Cos[θ/4]],  2 Abs[Sin[θ/4]]];

f[θ1_,  θ2_] := 
        d[θ1]  +  d[θ2]  -  
          d[θ1  +  θ2];

Plot3D[
        f[θ1, θ2],  {θ1,  0,  2  Pi},  {θ2,  
          0,  2  Pi},  PlotPoints -> 30];

ContourPlot[
        f[θ1, θ2],  {θ1,  0,  2  Pi},  {θ2,  
          0,  2  Pi},  PlotPoints -> 50,  Contours -> 20,  
        PlotRange -> All];

Note from the two plots, that f(θ1, θ2) is always greater than zero.