EEL6667 Chapter 2 examples

This notebook gives some basic rotation and homogeneous transformation definitions and illustrates their use on some examples from the textbook (Chapter 2).

Generic definitions

Turn off annoying warnings messages

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

Load in necessary packages

<< LinearAlgebra`MatrixManipulation`;

Nice view of matrices and vectors

Nice[m_] := m // MatrixForm  //  TraditionalForm

Elementary rotation and transform definitions

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}};

Convert a 3x3 rotation matrix and a 3x1 position vector to a 4x4 homogeneous operator

RAndPToT[r_,  p_] := 
Join[
          Transpose[Join[Transpose[r],  {p}]], {{0, 0, 0, 1}}];

Convert a 3x3 rotation matrix to 4x4 homogeneous rotational operator

RToT[r_] := RAndPToT[r,  {0, 0, 0}];

Elementary homogeneous rotational operators

RX[a_] := RToT[rX[a]];
RY[a_] := RToT[rY[a]];
RZ[a_] := RToT[rZ[a]];

Angle-axis rotation [(Subscript[R, k])(θ)]

RK[θ_,  
          k_] := 
Module[{kx,  ky, kz,  v, c, 
            s}, 
{kx,  ky,  kz}  =  
            k/Sqrt[k . k]; {{kx^2 v  +  c, kx ky v  -  kz s,  
                kx kz v  +  ky s}, {kx ky v  +  kz s,  
                ky^2 v +  c,  
                ky kz v  -  kx s}, {kx kz v  -  ky s,  
                ky kz v  +  kx s,  
                kz^2 v  +  c}}  /.  {v -> (1 - Cos[θ]),  
              c -> Cos[θ],  s -> Sin[θ]}];

Convert a 3x1 position vector to a 4x4 homogeneous translational operator

PToT[p_] := RAndPToT[IdentityMatrix[3],  p];

Elementary homogeneous translational operators

DX[x_] := PToT[{x, 0, 0}];
DY[y_] := PToT[{0, y, 0}];
DZ[z_] := PToT[{0, 0, z}];

Extract 3x3 rotation matrix from 4x4 homogeneous transform

RFromT[t_] := TakeMatrix[t, {1, 1}, {3, 3}];

Extract 3x1 position vector from 4x4 homogeneous transform

PFromT[t_] := 
        TakeMatrix[t, {1, 4}, {3, 4}]  //  Flatten;

Compute inverse of a 4x4 homogeneous transform

InverseT[
          t_] := 
Module[{r,  
            p}, 
r  =  
            RFromT[t]; 
p  =  
            PFromT[t]; 
RAndPToT[
            Transpose[
              r],  -Transpose[r] . p]
];

Craig text examples

Example 2.1

RAB  =  rZ[30 Degree]  //  N;
RAB  //  Nice

PB  =  {0. ,  2. ,  0. };
PB  //  Nice

PA  =  RAB . PB;
PA  //  Nice

Example 2.2

TAB  =  
        DX[10] . DY[5] . RZ[30 Degree]  //  
          N;
TAB  //  Nice

PB  =  {3. , 7. , 0. , 1. };
PB  //  Nice

PA  =  TAB . PB;
PA  //  Nice

Example 2.3

R  =  rZ[30 Degree];
R  //  Nice

PA1  =  {0, 2, 0};
PA1  //  Nice

PA2  =  R . PA1;
PA2  //  Nice

Example 2.4

Trans  =  
        DY[5] . DX[10] . RZ[30 Degree];
Trans  //  Nice

PA1  =  {3, 7, 0, 1};
PA1  //  Nice

PA2  =  Trans . PA1;
PA2  //  N  //  Nice

Example 2.5

TAB  =  
        DY[3] . DX[4] . RZ[30 Degree];
TAB  //  Nice

TBA  =  InverseT[TAB];
TBA  //  Nice
TBA  //  N  //  Nice

Example 2.7

R1  =  rZ[30 Degree];  R1  //  Nice

R2  =  rX[30 Degree];  R2  //  Nice

R12  =  R1 . R2;  R12  //  Nice

R21  =  R2 . R1;  R21  //  Nice

R21  ==  R12

Example 2.8

RAB  =  
        RK[30 Degree, {1, 1, 0}/Sqrt[2]]  //  
          Simplify;
TAB  =  RToT[RAB];
TAB  //  Nice
TAB  //  N  //  Nice

Example 2.9

TAAp  =  DX[1] . DY[2] . DZ[3];  TAAp  //  Nice

TApBp  =  
        RToT[RK[30 Degree,  {1, 1, 0}/Sqrt[2]]]  //  
          Simplify;
TApBp  //  Nice

TBpB  =  
        DX[-1] . DY[-2] . DZ[-3];
TBpB  //  Nice

TAB  =  
        TAAp . TApBp . TBpB  //  Simplify;
TAB  //  Nice
TAB  //  N  //  Nice

Other examples

XYZ Fixed angles (ZYX Euler)

RXYZFixed  =  rZ[α] . rY[β] . rX[γ];  
    RXYZFixed  //  Nice

ZYZ Euler angles

RZYZEuler  =  rZ[α] . rY[β] . rZ[γ];  
    RZYZEuler  //  Nice

Derivation of equivalent angle-axis rotation matrix

Multiply elementary rotation matrices

rk  = 
        rZ[α] . rY[β] . rZ[θ] . rY[-β] . 
          rZ[-α];
rk  //  Nice

Substitute angles in terms of \(TraditionalForm\`\(k\&^\)\)

\(\(substitutionRules\  = \ {Cos[α]\  -> 
            kx/Sqrt[kx^2\  + \ ky^2], 
		Sin[α]\  -> \ 
            ky/Sqrt[kx^2\  + \ ky^2], 
		Cos[β]\  -> kz, \ 
          Sin[β] -> 
            Sqrt[kx^2\  + \ ky^2]};\)\)
substitutionRules  //  Nice

rk2  = rk  /.  substitutionRules;
rk2  //  Nice

Simplify, for cryin' out loud!

rk3  =  Simplify[rk2];
rk3  //  Nice

Fine tune...

subRule2  =  
        kz^2  ->  (1 - kx^2 - ky^2);
subRule3  =  (kx^2  +  ky^2)  ->  (1 - 
              kz^2);
rk4  =  
        rk3  /. subRule2  //  Simplify;
rksub33  =  
        rk3[[3, 3]]  /.  subRule3  //  
          Simplify;
rk4  =  
        ReplacePart[rk4,  rksub33,  {3, 3}];
rk4  //  Nice