In [1]:

from miscpy.utils.sympyhelpers import *
init_printing()
th,n1,n2,n3 = symbols('theta,n_1,n_2,n_3')



# Simple Rotations

## Example 1: Rotation about 3rd body axis

$\mathbf{\hat{n}} = \mathbf{a}_3 = \mathbf{b}_3$



In [5]:

n = Matrix([0,0,1]);n




Out[5]:

$$\left[\begin{matrix}0\\0\\1\end{matrix}\right]$$



${}^\mathcal{A}C^\mathcal{B} = \cos\theta I + (1 - \cos\theta) [\mathbf{\hat{n}}][\mathbf{\hat{n}}]^T + \sin\theta [\mathbf{\hat{n}}\times]$:



In [9]:

aCb = cos(th)*eye(3) + (1 - cos(th))*(n*n.T) + sin(th)*skew(n); aCb




Out[9]:

$$\left[\begin{matrix}\cos{\left (\theta \right )} & - \sin{\left (\theta \right )} & 0\\\sin{\left (\theta \right )} & \cos{\left (\theta \right )} & 0\\0 & 0 & 1\end{matrix}\right]$$



As a sanity check, show that ${}^\mathcal{B}C^\mathcal{A} [\mathbf{\hat{n}}] = [\mathbf{\hat{n}}]$



In [8]:

aCb.T*n




Out[8]:

$$\left[\begin{matrix}0\\0\\1\end{matrix}\right]$$



## Example 2: Rotating about $1 \mathbf{b}_1 + 2 \mathbf{b}_2 + 3 \mathbf{b}_3$



In [10]:

n2 = Matrix([1,2,3])
n2 = n2/n2.norm()
n2




Out[10]:

$$\left[\begin{matrix}\frac{\sqrt{14}}{14}\\\frac{\sqrt{14}}{7}\\\frac{3 \sqrt{14}}{14}\end{matrix}\right]$$




In [11]:

aCb2 = cos(th)*(eye(3) - n2*n2.T)+ n2*n2.T + sin(th)*skew(n2); aCb2




Out[11]:

$$\left[\begin{matrix}\frac{13 \cos{\left (\theta \right )}}{14} + \frac{1}{14} & - \frac{3 \sqrt{14} \sin{\left (\theta \right )}}{14} - \frac{\cos{\left (\theta \right )}}{7} + \frac{1}{7} & \frac{\sqrt{14} \sin{\left (\theta \right )}}{7} - \frac{3 \cos{\left (\theta \right )}}{14} + \frac{3}{14}\\\frac{3 \sqrt{14} \sin{\left (\theta \right )}}{14} - \frac{\cos{\left (\theta \right )}}{7} + \frac{1}{7} & \frac{5 \cos{\left (\theta \right )}}{7} + \frac{2}{7} & - \frac{\sqrt{14} \sin{\left (\theta \right )}}{14} - \frac{3 \cos{\left (\theta \right )}}{7} + \frac{3}{7}\\- \frac{\sqrt{14} \sin{\left (\theta \right )}}{7} - \frac{3 \cos{\left (\theta \right )}}{14} + \frac{3}{14} & \frac{\sqrt{14} \sin{\left (\theta \right )}}{14} - \frac{3 \cos{\left (\theta \right )}}{7} + \frac{3}{7} & \frac{5 \cos{\left (\theta \right )}}{14} + \frac{9}{14}\end{matrix}\right]$$




In [13]:

simplify(aCb2.T*n2 - n2)




Out[13]:

$$\left[\begin{matrix}0\\0\\0\end{matrix}\right]$$




In [17]:

simplify(aCb2*n2 - n2)




Out[17]:

$$\left[\begin{matrix}0\\0\\0\end{matrix}\right]$$




In [ ]:



## Example 3: Rotating about aribtary axis $n_1 \mathbf{b}_1 + n_2 \mathbf{b}_2 + n_3 \mathbf{b}_3$



In [18]:

n1,n2,n3 = symbols('n_1,n_2,n_3')




In [19]:

ng = Matrix([n1,n2,n3]);ng




Out[19]:

$$\left[\begin{matrix}n_{1}\\n_{2}\\n_{3}\end{matrix}\right]$$




In [20]:

aCbg = simplify(cos(th)*eye(3) + (1 - cos(th))*(ng*ng.T) + sin(th)*skew(ng)); aCbg




Out[20]:

$$\left[\begin{matrix}n_{1}^{2} \left(- \cos{\left (\theta \right )} + 1\right) + \cos{\left (\theta \right )} & - n_{1} n_{2} \left(\cos{\left (\theta \right )} - 1\right) - n_{3} \sin{\left (\theta \right )} & - n_{1} n_{3} \left(\cos{\left (\theta \right )} - 1\right) + n_{2} \sin{\left (\theta \right )}\\- n_{1} n_{2} \left(\cos{\left (\theta \right )} - 1\right) + n_{3} \sin{\left (\theta \right )} & n_{2}^{2} \left(- \cos{\left (\theta \right )} + 1\right) + \cos{\left (\theta \right )} & - n_{1} \sin{\left (\theta \right )} - n_{2} n_{3} \left(\cos{\left (\theta \right )} - 1\right)\\- n_{1} n_{3} \left(\cos{\left (\theta \right )} - 1\right) - n_{2} \sin{\left (\theta \right )} & n_{1} \sin{\left (\theta \right )} - n_{2} n_{3} \left(\cos{\left (\theta \right )} - 1\right) & n_{3}^{2} \left(- \cos{\left (\theta \right )} + 1\right) + \cos{\left (\theta \right )}\end{matrix}\right]$$




In [ ]: