# 3 Rotations to unit vector (3D)

I've been trying to solve this problem for some time now, but I could really need some help:

I have 3 rotations (one per axis) for an object, and want to create a unit vector telling me in which direction the object is pointing.

How do I achive this?

-
I think you just take the direction (as a vector) in which the object is pointing in its initial position and then apply these 3 rotation. How do you define the pointing direction? –  Ilya Sep 22 '11 at 13:38
Rotation matrix can be applied here to solve your problem. However, I'd suggest you to solve your problem is such way: build a local coordinate attached on your object, and applied rotation matrices to each basis vector of your local coordinate. And the rotation is w.r.t. some reference coordinates. –  newbie Sep 22 '11 at 14:00

Let use assume we have a coordinate system, where e.g. $\mathtt e_x = \begin{bmatrix} 1\\0\\0 \end{bmatrix}$ points right, $\mathtt e_y = \begin{bmatrix} 0\\1\\0 \end{bmatrix}$ points down and $\mathtt e_z = \begin{bmatrix} 0\\0\\1 \end{bmatrix}$ points forward.

First, let us assume that the object of interest is aligned with the world. Thus, the transformation (=$3\times 3$ matrix) which maps points from the 'object' frame of reference into the world frame of reference is the identity:

$$\mathtt R_{wo} = \mathtt I.$$

Now, we rotate the object around the $x$-axis by $\theta_x$, then the $y$-axis by $\theta_y$ and finally the $z$-axis by $\theta_z$:

$$\mathbf R_{wo'} = \mathbf R_{wo} \exp(\theta_x\mathbf G_x)\exp(\theta_y\mathbf G_y)\exp(\theta_z\mathbf G_z)$$ $$= \exp(\theta_x\mathbf G_x)\exp(\theta_y\mathbf G_y)\exp(\theta_z\mathbf G_z)$$

Excursus: What is $\exp(\theta_i\mathbf G_i)$?

Generally speaking, $\exp$ is the matrix exponential and $\mathbf G_x=\begin{bmatrix}0 & 0& 0\\0 & 0& -1\\0 & 1& 0\end{bmatrix}$, $\mathbf G_y=\begin{bmatrix}0 & 0& 1\\0 & 0& 0\\-1 & 0& 0\end{bmatrix}$, $\mathbf G_z=\begin{bmatrix}0 & -1& 0\\1 & 0& 0\\0 & 0& 0\end{bmatrix}$ are the generators of the Lie algebra so(3).

For so(3), the matrix exponential can be calculated using the Rodrigues formula: $$\exp (\theta_i \mathbf G_i) = \mathtt I + \mathtt G_i\sin(\theta_i) + \mathtt G_i^2(1-\cos(\theta_i))$$

For instance: $\exp(\theta_x\cdot \mathtt G_x) = \mathtt I +\begin{bmatrix}0 & 0& 0\\0 & 0& -1\\0 & 1& 0\end{bmatrix}\sin(\theta_x) + \begin{bmatrix}0 & 0& 0\\0 & -1& 0\\0 & 0& -1\end{bmatrix}(1-\cos(\theta_x))$

$\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad=\begin{bmatrix}1 & 0& 0\\0 & \cos(\theta_x)& -\sin(\theta_x)\\0 & \sin(\theta_x)& \cos(\theta_x)\end{bmatrix}$

(Note that rotations do not commute, so that the order of applying rotations matters. In other words: $\exp(\theta_x\mathbf G_x)\exp(\theta_y\mathbf G_y)\neq\exp(\theta_y\mathbf G_y)\exp(\theta_x\mathbf G_x)$)

To transform a point in the object frame $\mathbf x_{o'}$ to the corresponding point in the world frame $\mathbf x_w$ we do: $\mathbf x_w = \mathtt R_{wo'}\mathbf x_{o'}$.

Thus, we can for instance transform the forward direction in the object coordinate frame $\mathbf e_z$ to the forward direction $\mathbf x_{\text{forward}}$ in world coordinates:

$$\mathbf x_{\text{forward}} = \mathtt R_{wo'}\mathbf e_{z}$$

-
Great answer! Just what I needed :) –  RasmusWriedtLarsen Sep 27 '11 at 12:45

If the object is pointing towards the $\hat{k}$ direction before the rotation, then it is pointing towards

$$\hat{k}_{world} = {\rm R_1 R_2 R_3} \hat{k}$$

where $\rm R_i$, i=1..3 are the three rotations.

-