%
%  2004/Lecture notes/Lecture6/lecture6.tex
%
\documentclass[pdf,mmoll,slideColor%,colorBG
]{prosper}
\RequirePackage{color}

\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,natbib}
%\usepackage[T1,noTS1]{mathtime}
\SetMathAlphabet{\mathbf}{normal}{\encodingdefault}{ptm}{b}{n}
\usepackage{subfigure}
\usepackage{rotating}
\usepackage{graphicx}
%\usepackage[dvips]{color}
\usepackage{epsfig}
\graphicspath{{../figs/}}

\newcommand{\ee}{\end{equation}} 
\newcommand{\be}{\begin{equation}} 
\newcommand{\ec}{\end{center}} 
\newcommand{\bc}{\begin{center}} 
\newcommand{\eea}{\end{eqnarray}} 
\newcommand{\bea}{\begin{eqnarray}} 
%\newcommand{\sumprime}{\mathop{{\sum}'}} 
\newcommand{\bd}{\begin{description}} 
\newcommand{\ed}{\end{description}} 
\newcommand{\bi}{\begin{itemize}} 
\newcommand{\ei}{\end{itemize}} 
\newcommand{\pa}{\partial} 
\newcommand{\hor}{\left(\frac{h}{R_0}\right)} 

\newcommand{\code}[0]{\ttfamily}
\newcommand{\co}[0]{\hbox{c}}
\newcommand{\si}[0]{\hbox{s}}
\newcommand{\pprime}[0]{\prime\prime}
\newcommand{\ppprime}[0]{\prime\prime\prime}
\newcommand{\conv}{\operatorname{conv}}
\newcommand{\pos}{\operatorname{pos}}
\newcommand{\lin}{\operatorname{lin}}
\newcommand{\vertop}{\operatorname{vert}}
\newcommand{\spanop}{\operatorname{span}}
\newcommand{\supp}{\operatorname{supp}}
\newcommand{\intoper}{\operatorname{int}}
\newcommand{\half}{\operatorname{half}}
\newcommand{\rad}{\operatorname{rad}}
\newcommand{\diam}{\operatorname{diam}}
\newcommand{\push}{\operatorname{push}}
\newcommand{\sqz}{\operatorname{sqz}}
\newcommand{\sgn}{\operatorname{sgn}}
%\renewcommand{\Re}{\Bbb{R}}
\renewcommand{\Re}{\mathbf{R}}
\newcommand{\vv}[1]{\mathbf{#1}}
\newcommand{\uu}[1]{\hat {\vv #1}}
\newcommand{\defterm}[1]{\textbf{#1}}
\newcommand{\rot}{\operatorname{rot}}

\newcommand{\btimes}{\times}
\newcommand{\bomega}{\omega}

 
\newcommand{\bis}{\begin{itemstep}} 
\newcommand{\eis}{\end{itemstep}} 

\makeatletter
\define@key{PDF}{Movie}{\pdf@addtoks{#1}{Movie}}
\define@key{PDF}{Activation}{\pdf@addtoks{#1}{Activation}}
\newcommand{\moviewithpreview}[3]{% args: width, preview, movie
   \pdfmark[{\includegraphics[width=#1]{#2}}]{%
   pdfmark=/ANN,Subtype=/Movie,Movie=<< /F (#3) >>,%
   Activation=<< /ShowControls true /Mode /Repeat >>}}
\newcommand{\movie}[3]{% args:width, height, movie
   \pdfmark[{\hbox to #1 {\vbox to #2 { }}}]{%
   pdfmark=/ANN,Subtype=/Movie,Movie=<< /F (#3) /Poster true >>,%
   Activation=<< /ShowControls true /Mode /Repeat >>}}
\makeatother

\title{6.  Representing Rotation}
\subtitle{ Mechanics of Manipulation}
\author{Matt Mason}
\institution{Carnegie Mellon}
\email{matt.mason@cs.cmu.edu \\
http://www.cs.cmu.edu/\symbol{"7E}mason}
\slideCaption{Lecture 6. \hfill Mechanics of Manipulation }

\begin{document}

\maketitle



%=======================================================================
%
% SLIDE 2
%

\begin{slide}[R]{Lecture 6.  Representing Rotation.}
\vspace{-0.5in}
\includegraphics[height=3.0in]{TOC6}
\end{slide}

%=======================================================================
%
% SLIDE 3
%
%

\begin{slide}[R]{Outline.}

\begin{itemize}
\item Generalities
\item Axis-angle
\item Rodrigues's formula
\item Rotation matrices
\item Euler angles
\end{itemize}

\end{slide}


%=======================================================================
%
% SLIDE 4
%
%
\begin{slide}[R]{Why representing rotations is hard.}

\begin{itemize}
\item
        Rotations do not commute.

\item
        The topology of spatial rotations does not permit a smooth
        embedding in Euclidean three space.

\end{itemize}

\end{slide}
%=======================================================================
%
% SLIDE 5
%
%
\begin{slide}[R]{Choices}

\begin{itemize}
\item
        More than three numbers
  \begin{itemize}
  \item  Rotation matrices
  \item Unit quaternions.  (aka Euler parameters)
  \end{itemize}

\item
          Many-to-one
  \begin{itemize}
  \item Axis times angle (matrix exponential)
  \end{itemize}

\item
        Unsmooth and many-to-one
  \begin{itemize}
  \item  Euler angles
  \end{itemize}

\item
        Unsmooth and many-to-one and more than three numbers
  \begin{itemize}
  \item Axis-angle
  \end{itemize}

\end{itemize}

\end{slide}

%========================================================================
%
% SLIDE 6
%
%

\begin{slide}[R]{Axis-angle}

\begin{minipage}[t]{6cm}
Recall Euler's theorem:  every spatial rotation leaves a line of fixed points:  the rotation axis.
\begin{itemize}
\item[]  Let $O$, $\uu n$, $\theta$, be $\ldots$
\item[] Let $\rot(\uu n, \theta)$ be the corresponding rotation.
\end{itemize}
Many to one:  
\begin{itemize}
\item[]$\rot(- \uu n,- \theta) = \rot(\uu n, \theta)$
\item[]$\rot(\uu n, \theta + 2 k \pi) = \rot(\uu n, \theta)$, for any integer
$k$.  
\item [] When $\theta = 0$, the rotation axis is
indeterminate, giving an infinity-to-one mapping.
\end{itemize}

\end{minipage}
\hfill
\begin{minipage}[t]{4cm}
\begin{figure}[h!]
\includegraphics[width=4cm]{axis_angle.eps}
\end{figure}
\end{minipage}
\end{slide}

%========================================================================
%
% SLIDE 7
%
%
\begin{slide}[R]{Representation}
What do we want from a representation?  For a start:
\begin{itemize}
\item Rotate points;
\begin{itemize}
\item[]  Rodrigues's formula
\end{itemize}
\item Compose rotations;
\begin{itemize}
\item[]  Using axis-angle?  Ugh.
\end{itemize}
\item (Convert to other representations.)
\end{itemize}
\end{slide}

%=======================================================================
%
% SLIDE 8
%
%

\begin{slide}[R]{Rodrigues's formula}

\begin{minipage}[t]{6cm}
Others derive Rodrigues's formula using rotation matrices, missing the
geometrical aspects.  
\begin{itemize}
\item[] Given point $\vv x$, decompose
into components parallel and perpendicular to the
rotation axis
     \[
        \vv x = \uu n( \uu n \cdot \vv x) - 
                  \uu n \btimes ( \uu n \btimes \vv x )
    \]
\item[]

Only $\vv x_\perp$ is affected by the rotation, yielding
\emph{Rodrigues's formula}: 
    \[
        \vv x^\prime = \uu n (\uu n \cdot \vv x) + \sin\theta \; ( \uu n \btimes \vv x )
                        - \cos\theta \; \uu n \btimes ( \uu n \btimes \vv x)
     \]
\item[] A common variation:
    \[
        \vv x^\prime = \vv x + ( \sin\theta ) \; \uu n \btimes \vv x 
                             + ( 1 - \cos\theta ) \; \uu n
                                        \btimes ( \uu n \btimes \vv x)
    \]

\end{itemize}
\end{minipage}
\hfill
\begin{minipage}[t]{4cm}
\begin{figure}[h!]
\includegraphics[width=4cm]{rodriguez.eps}
\end{figure}
\end{minipage}
\end{slide}
%=======================================================================
%
% SLIDE 9
%
%

\begin{slide}[R]{Rotation matrices}

\begin{itemize}
\item[]Choose $O$ on rotation axis.  Choose frame $(\uu u_1, \uu u_2,
\uu u_3)$.

\item[] Let $(\uu u_1^\prime, \uu u_2^\prime, \uu
u_3^\prime)$ be the image of that frame.

\item[] Write the
$\uu u_i^\prime$ vectors in $\uu u_i$ coordinates, and collect them in
a matrix:
\begin{align*}
 \uu u_1^\prime &= \left(\begin{array}{c} a_{11} \\ a_{21} \\ a_{31} \end{array}\right)
                = \left(\begin{array}{c} \uu u_1 \cdot \uu u_1^\prime \\
                                \uu u_2 \cdot \uu u_1^\prime \\
                                \uu u_3 \cdot \uu u_1^\prime
                         \end{array}\right) \\
 \uu u_2^\prime &= \left(\begin{array}{c} a_{12} \\ a_{22} \\ a_{32} \end{array}\right)
                = \left(\begin{array}{c} \uu u_1 \cdot \uu u_2^\prime \\
                                \uu u_2 \cdot \uu u_2^\prime \\
                                \uu u_3 \cdot \uu u_2^\prime
                         \end{array}\right) \\
 \uu u_3^\prime &= \left(\begin{array}{c} a_{13} \\ a_{23} \\ a_{33} \end{array}\right)
                = \left(\begin{array}{c} \uu u_1 \cdot \uu u_3^\prime \\
                                \uu u_2 \cdot \uu u_3^\prime \\
                                \uu u_3 \cdot \uu u_3^\prime
                         \end{array}\right) 
\end{align*}
\[
        A = \left(a_{ij}\right) = \left( \uu u_1^\prime | \uu u_2^\prime | \uu u_3^\prime \right)
\]

\end{itemize}
\end{slide}

%=======================================================================
%
% SLIDE 9
%
%

\begin{slide}[R]{So many numbers}

\begin{itemize}
\item[] A rotation matrix has nine numbers, 
\item[] but spatial rotations have only three degrees of freedom, 
\item[] leaving six excess numbers $\ldots$
\item[] There are six constraints that hold among the nine numbers.
\begin{align*}
         | \uu u_1^\prime | &= | \uu u_2^\prime | = | \uu u_3^\prime | = 1 \\
         \uu u_3^\prime &= \uu u_1^\prime \btimes \uu u_2^\prime
\end{align*}
\item[] \emph{i.e.} the $\uu u_i^\prime$ are unit vectors forming a
right-handed coordinate system.  
\item[] Such matrices are called \emph{orthonormal} or \emph{rotation} matrices.
\end{itemize}
\end{slide}

%=======================================================================
%
% SLIDE 10
%
%

\begin{slide}[R]{Rotating a point}
\begin{itemize}
\item[]  Let  $(x_1, x_2, x_3)$ be coordinates of $\vv x$ in frame $(\uu u_1, \uu u_2, \uu u_3)$. \item[]  Then $\vv x^\prime$ is given by the same coordinates taken in
the $(\uu u_1^\prime, \uu u_2^\prime, \uu u_3^\prime)$ frame: 
\begin{align*}
  \vv x^\prime  = & x_1 \uu u_1^\prime
                         + x_2 \uu u_2^\prime
                         + x_3 \uu u_3^\prime \\
                 = & x_1 A \uu u_1 + x_2 A \uu u_2 + x_3 A \uu u_3 \\
                 = & A ( x_1 \uu u_1 + x_2 \uu u_2 + x_3 \uu u_3 ) \\
                 = & A \vv x
\end{align*}
\item[] So rotating a point is implemented by ordinary matrix multiplication.
\end{itemize}

\end{slide}

%=======================================================================
%
% SLIDE 11
%
%

\begin{slide}[R]{Rotating a point}
\begin{itemize}
\item[]
  Let $A$ and $B$ be coordinate frames.  Notation:
  \begin{tabular}{c@{\hspace{.25in}}p{4in}}
        $x$ & a point \\
        $\vv x$ & a geometrical vector, directed from an origin $O$ to the
                 point $x$; or, a vector of three numbers, representing
                 $x$ in an unspecified frame\\
        $^A\vv x$ & a vector of three numbers, representing $x$ in the
                 $A$ frame 
  \end{tabular}
\item[] Let $^B_A \! R$ be the rotation matrix that rotates frame $B$ to frame $A$\@.  
\item[] Then (see previous slide) $^B_A \! R$ represents the rotation of the point $x$:
\[
        ^B\vv x^\prime = {^B_A \! R} \; {^B\vv x}
\]
\item[] Note presuperscripts all match.  Both points, and xform, must be written in same
coordinate frame.
\end{itemize}
\end{slide}

%=======================================================================
%
% SLIDE 12
%
%

\begin{slide}[R]{Coordinate transform}
There is another use for $^B_A\!R$:
\begin{itemize}
\item[]  $^A\vv x$ and $^B\vv x$ represent the same point, in frames $A$ and $B$ resp.
\item[] To transform from $A$ to $B$:
  \[
        ^B\vv x = {^B_A \! R} \; {^A\vv x}
  \]
\item[] For coord xform, matrix subscript and vector superscript ``cancel''.
\end{itemize}
Rotation from $B$ to $A$ is the same as coordinate transform from $A$ to $B$.
\end{slide}

%=======================================================================
%
% SLIDE 13
%
%

\begin{slide}[R]{Example rotation matrix}
\begin{minipage}[t]{6cm}
\begin{align*}
  ^B_A\!R &= \left(\begin{array}{c|c|c}
                        ^B{\vv x}_A & ^B{\vv y}_A & ^B{\vv z}_A 
                               \end{array}\right) \\
                  &= \left(\begin{array}{ccc}
                        1 & 0 & 0 \\
                        0 & 0 & -1 \\
                        0 & 1 & 0 
                                \end{array}\right)
\end{align*}
How to remember what $^B_A\!R$ does?  Pick a coordinate axis and see.  The
$x$ axis isn't very interesting, so try $y$:
\[
                  \left(\begin{array}{ccc}
                        1 & 0 & 0 \\
                        0 & 0 & -1 \\
                        0 & 1 & 0 
                                \end{array}\right)
                \left(\begin{array}{c} 0 \\ 1 \\ 0 \end{array}\right)
                = \left(\begin{array}{c} 0 \\ 0 \\ 1 \end{array}\right)
\]
\end{minipage}
\hfill
\begin{minipage}[t]{4cm}
\begin{figure}[h!]
\includegraphics[height=6cm]{labelExampleRot}
\end{figure}
\end{minipage}
\end{slide}
%=======================================================================
%
% SLIDE 14
%
%

\begin{slide}[R]{Nice things about rotation matrices}
\begin{itemize}
\item  Composition of rotations:  $\{R_1; R_2\} = R_2 R_1$.  \\
($\{ x; y\}$ means do $x$ then do $y$.)
\item  Inverse of rotation matrix is its transpose $^B_A\!R^{-1} 
  = {^A_B\!R}
  = {^B_A\!R^T}$.
\item  Coordinate xform of a rotation matrix:
  \[
        ^B\!R = {^B_A\!R} \, {^AR} \, {^A_B\!R}
\]
\end{itemize}
\end{slide}

%=======================================================================
%
% SLIDE 15
%
%

\begin{slide}[R]{Converting $\rot(\uu n, \theta)$ to $R$}
\begin{itemize}
\item[]
Ugly way:  define frame with $\uu z$ aligned with $\uu n$, use coordinate xform of previous
slide.

\item[]
Keen way:  Rodrigues's formula!
\[
 \vv x^\prime = \vv x + ( \sin\theta ) \; \uu n \btimes \vv x
+ ( 1 - \cos\theta ) \; \uu n \btimes ( \uu n \btimes \vv x)
\]

\item[]
Define ``cross product matrix'' $N$:
\[
 N = \left(\begin{array}{ccc}
                0 & -n_3 & n_2 \\
                n_3 & 0 & -n_1 \\
                -n_2 & n_1 & 0 \\ \end{array}\right)
\]
so that
\[
        N {\vv x} = \uu n \btimes {\vv x}
\]
\end{itemize}
\end{slide}

%=======================================================================
%
% SLIDE 16
%
%

\begin{slide}[R]{$\ldots$ using Rodrigues's formula $\ldots$}
\begin{itemize}
\item[] Substituting the cross product matrix $N$ into Rodrigues's formula:
\[
        \vv x^\prime = \vv x + ( \sin\theta ) N \vv x
                        + ( 1 - \cos\theta ) N^2 \vv x
\]
\item[]Factoring out $\vv x$
\[
        R = I + ( \sin\theta ) N + ( 1 - \cos\theta ) N^2
\]
\item[] That's it!  Rodrigues's formula in matrix form.  If you want to you could expand it:
\[
 \left(\begin{array}{ccc} 
                        n_1^2 + ( 1 - n_1^2 ) c\theta
                        & n_1 n_2 ( 1 - c\theta ) - n_3 s\theta
                        & n_1 n_3 ( 1 - c\theta ) + n_2 s\theta \\
                 n_1 n_2 ( 1 - c\theta) + n_3 s\theta
                        & n_2^2 + ( 1 - n_2^2 ) c\theta
                        & n_2 n_3 ( 1 - c\theta ) - n_1 s\theta \\
                 n_1 n_3 ( 1 - c\theta ) - n_2 s\theta
                        & n_2 n_3 ( 1 - c\theta ) + n_1 s\theta
                        & n_3^2 + (1 - n_3^2 ) c\theta \\
                \end{array}\right)
\]
where $c\theta = \cos\theta$ and $s\theta = \sin\theta$.  Ugly.  

\end{itemize}
\end{slide}

%=======================================================================
%
% SLIDE 18
%
%

\begin{slide}[R]{Rodrigues's formula for differential rotations}
Consider Rodrigues's formula for a differential rotation
$\rot(\uu n, d\theta)$.
\begin{align*}
  {\vv x}^\prime  = & (I + \sin d\theta N + (1 - \cos d\theta) N^2 ) {\vv x} \\
                  = & (I + d\theta N ) {\vv x}
\end{align*}
so
\begin{align*}
        d\vv x  = & N {\vv x} \, d\theta \\
                = & \uu n \btimes {\vv x} \, d\theta
\end{align*}
It follows easily that differential rotations are vectors: you can scale them and add them up.  We adopt the convention of representing angular velocity by the unit vector $\uu n$ times the angular velocity.

\end{slide}

%=======================================================================
%
% SLIDE 17
%
%

\begin{slide}[R]{Converting from $R$ to $\rot(\uu n,\theta) \ldots$}
\begin{itemize}
\item[]  Problem:  $\uu n$ isn't defined for $\theta = 0$.
\item[]  We will do it indirectly.  Convert $R$ to a unit quaternion (next lecture), then
to axis-angle.
\end{itemize}
\end{slide}

%========================================================================
%
% SLIDE 18
%
%

\begin{slide}[R]{Euler angles}
\begin{minipage}[t]{6cm}
\begin{itemize}
\item[]  Three numbers to describe spatial rotations.  $ZYZ$ convention:
\[
        (\alpha, \beta, \gamma) \mapsto 
                \rot(\gamma, \uu z^{\pprime}) 
                \rot(\beta, \uu y^\prime) 
                \rot(\alpha, \uu z)
\]

\item[]  Can we represent an arbitrary rotation?
\begin{verse}
        Rotate $\alpha$ about $\uu z$ until $\uu y^\prime \perp \uu z^{\ppprime}$;\\
        Rotate $\beta$ about $\uu y^\prime$ until $\uu z^{\pprime} \parallel
                \uu z^{\ppprime}$;\\
        Rotate $\gamma$ about $\uu z^{\pprime}$ until $\uu y^{\pprime} =
                \uu y^{\ppprime}$.
\end{verse}
\item[]  Note two choices for $\uu y^\prime$ \ldots
\item[]  \ldots except sometimes infinite choices.

\end{itemize}

\end{minipage}
\hfill
\begin{minipage}[t]{4cm}
\begin{figure}[h!]
\includegraphics[width=4cm]{eangles}
\end{figure}
\end{minipage}
\end{slide}

%=======================================================================
%
% SLIDE 19
%
%

\begin{slide}[R]{From $(\alpha, \beta, \gamma)$ to $R$}
\begin{itemize}
\item[]  Expand $ \rot(\alpha, \uu z) 
                \rot(\beta, \uu y) 
                \rot(\gamma, \uu z)$

\item[] (Why is that the right order?)
\item[]
\begin{multline}
 \left(\begin{array}{ccc}
        \co\alpha & -\si\alpha & 0 \\
        \si\alpha & \co\alpha & 0 \\
        0 & 0 & 1 \\
        \end{array}\right)
 \left(\begin{array}{ccc}
        \co\beta & 0 & \si\beta \\
        0        & 1 & 0 \\
        -\si\beta & 0 & \co\beta \\
        \end{array}\right) 
 \left(\begin{array}{ccc}
        \co\gamma & -\si\gamma & 0 \\
        \si\gamma & \co\gamma & 0 \\
        0        & 0             & 1 \\
        \end{array}\right) \\ 
 = \left(\begin{array}{ccc}
  \co\alpha \, \co\beta \, \co\gamma - \si\alpha \, \si\gamma
         & -\co\alpha \, \co\beta \, \si\gamma - \si\alpha \, \co\gamma
         & \co\alpha \, \si\beta \\
  \si\alpha \, \co\beta \, \co\gamma + \co\alpha \, \si\gamma
                & -\si\alpha \, \co\beta \, \si\gamma + \co\alpha \, \co\gamma
                & \si\alpha \, \si\beta \\
  -\si\beta \, \co\gamma & \si\beta \, \si\gamma & \co\beta \\
        \end{array}\right) \label{eq:eulermat}
\end{multline}
\end{itemize}
\end{slide}
 
%=======================================================================
%
% SLIDE 20
%
%

\begin{slide}[R]{From $R$ to $(\alpha,\beta,\gamma)$ the ugly way}
\begin{itemize}
\item[] Case 1:  $r_{33} = 1$, $\beta = \pi$.   $\alpha - \gamma$ is indeterminate.
\[ R=  \left(\begin{array}{ccc}
               \cos(\alpha+\gamma) & -\sin(\alpha + \gamma) & 0 \\
               \sin(\alpha+\gamma) & \cos(\alpha+\gamma) & 0 \\
               0 & 0 & 1 \\
               \end{array} \right) \]
\item[] Case 2:  $r_{33} = -1$, $\beta = -\pi$.  $\alpha + \gamma$ is indeterminate.
\[ R =  \left(\begin{array}{ccc}
               - \cos(\alpha - \gamma) & -\sin(\alpha - \gamma) & 0 \\
               - \sin(\alpha - \gamma) & \cos(\alpha - \gamma) & 0 \\
               0 & 0 & 1 \\
               \end{array} \right) \]

\item[] For generic case:  solve 3rd column for $\beta$.  (Sign is free choice.)  Solve third
  column for $\alpha$ and third row for $\gamma$.

\item[] $\ldots$ but there are numerical issues $\ldots$
\end{itemize}
\end{slide}

%=======================================================================
%
% SLIDE 21
%
%

\begin{slide}[R]{From $R$ to $(\alpha,\beta,\gamma)$ the clean way}
\begin{itemize}
\item[]  Let
\begin{align*}
        \sigma & =  \alpha + \gamma \\
        \delta & =  \alpha - \gamma
\end{align*}

\item[]  Then
\begin{align*}
        r_{22} + r_{11} & =  \cos\sigma (1 + \cos\beta) \\
        r_{22} - r_{11} & =  \cos\delta (1 - \cos\beta) \\
        r_{21} + r_{12} & =  \sin\delta (1 - \cos\beta) \\
        r_{21} - r_{12} & =  \sin\sigma (1 + \cos\beta)
\end{align*}
(No special cases for $\cos\beta = \pm 1$?)

\item[]  Solve for $\sigma$ and $\delta$, then for $\alpha$ and
$\gamma$, then finally
\[  \beta = \tan^{-1}(r_{13} \cos\alpha + r_{23} \sin\alpha, r_{33})
\]
\end{itemize}
\end{slide}

%=======================================================================
%
% SLIDE 22
%

\begin{slide}[R]{Next:  Quaternions.}
\vspace{-0.5in}
\includegraphics[height=3.0in]{TOC7}
\end{slide}
\end{document}



\end{document}
