# API QuestionCalculating AROT question

##### Scientist
I have an RPOS and RVEL to Earth, for a DefSetStateEx call (using GPOS, GVEL of course). I want the AROT to orient the vehicle along the velocity vector, "right way up".

My thinking: Z-hat comes from normalized RVEL, X-hat comes from cross product of RPOS and RVEL, and Y-hat is then the cross product of Z-hat and X-hat.

From this, determine the three Euler angles to rotate the global coordinate frame to this desired orientation. But when I manually orient to the desired direction, and look at AROT from a GetStateEx, I get a totally different solution.

Has anyone been through this, and can lay out the math first, and then the implementation into Orbiter API?

TIA.

#### martins

##### Orbiter Founder
Orbiter Founder
This should be the coversion between rotation matrix R and the Euler angles stored in arot:

arot -> R:

$\begin{array}{ll} sinx = \sin(arot.x) & cosx = \cos(arot.x) \\ siny = \sin(arot.y) & cosy = \cos(arot.y) \\ sinz = \sin(arot.z) & cosz = \cos(arot.z) \end{array}$$R = \left[ \begin{array}{ccc} cosy cosz & cosy sinz & -siny \\ sinx siny cosz - cosx sinz & sinx siny sinz + cosx cosz & sinx cosy \\ cosx siny cosz + sinx sinz & cosx siny sinz - sinx cosz & cosx cosy \end{array} \right]$
and R -> arot:

$arot.x = \tan^{-1} \frac{R_{23}}{R_{33}}\qquad arot.y = -\sin^{-1} R_{13}\qquad arot.z = \tan^{-1}\frac{R_{12}}{R_{11}}$

##### Scientist
Thanks Martin - will try this and I'll report back.

Replies
1
Views
441
Replies
1
Views
649
SDK Question moveing cockpit camera
Replies
3
Views
478
Replies
1
Views
311
Replies
0
Views
501