Re: rotation angles from rotation matrix

• To: mathgroup at smc.vnet.net
• Subject: [mg80096] Re: rotation angles from rotation matrix
• From: sashap <pavlyk at gmail.com>
• Date: Sun, 12 Aug 2007 07:21:44 -0400 (EDT)
• References: <f9jjlf\$2hb\$1@smc.vnet.net>

```Hi Will,

the reason, I think, the solve was failing for inexact input is that
inexact matrix fails to satisfy the
same algebraic constraints that the symbolic does, hence Solve
concludes that there are no solutions:

In[64]:= m = {{0.977431, 0.158491, 0.139673}, {-0.0822761,
0.894559, -0.439311}, {-0.194572, 0.417905, 0.88741}};

In[66]:= Transpose[m].m - IdentityMatrix[3] // Norm

Out[66]= 1.38282*10^-6

In[10]:= rm[\[Phi]_, \[Theta]_, \[Psi]_] :=
RotationMatrix[\[Psi], {0, 1, 0}].RotationMatrix[\[Theta], {0, 0,
1}].RotationMatrix[\[Phi], {0, 1, 0}]

In[54]:= sm = rm[\[Phi], \[Theta], \[Psi]];

In[55]:= Transpose[sm].sm // Simplify

Out[55]= {{1,0,0},{0,1,0},{0,0,1}}

Now to how to find angles:

Observe that

In[59]:= sm[[2, 2]]

Out[59]= Cos[\[Theta]]

Thus

In[43]:= \[Theta]aprox = ArcCos[m[[2, 2]]]

Out[43]= 0.463353

Also

In[62]:= sm[[2, {1, 3}]]/Sin[\[Theta]]

Out[62]= {Cos[\[Phi]],Sin[\[Phi]]}

and thus we find another angle:

In[44]:= \[Phi]aprox =
Mod[ArcTan @@ (m[[2, {1, 3}]]/Sin[\[Theta]aprox]), 2 Pi]

Out[44]= 4.52725

And, finally,

In[63]:= sm[[{1, 3}, 2]]/Sin[\[Theta]]

Out[63]= {-Cos[\[Psi]],Sin[\[Psi]]}

In[48]:= \[Psi]aprox =
Mod[ArcTan @@ ({-1, 1}*m[[{1, 3}, 2]]/Sin[\[Theta]aprox]), 2 Pi]

Out[48]= 1.93329

Verify that the solution indeed gives your matrix back as much as it
is possible with machine numbers:

In[51]:= rm[\[Phi]aprox, \[Theta]aprox, \[Psi]aprox] - m // Norm

Out[51]= 1.35436*10^-6

Hope it helps,
Oleksandr Pavlyk
Wolfram Research

On Aug 11, 1:06 am, will <willpower... at hotmail.com> wrote:
> Dear Math forum,
>
> I found some useful code for retrieving the Euler angles of a rotation fr=
om a rotation matrix; see
>
> http://forums.wolfram.com/mathgroup/archive/2001/Aug/msg00286.html
>
> which goes as follows:
>
> In[1]:=
> Needs["Geometry`Rotations`"]
>
> In[2]:=
> B=RotationMatrix3D[Pi/3,Pi/4,Pi/6];
>
> In[3]:=
> Solve[RotationMatrix3D[=CF=95,=CE=B8,=CF=88]\[Equal]B,{=CF=95,=CE=B8,=CF=
=88}]
>
>  From In[3]:=
> Solve::ifun: Inverse functions are being used by Solve, so some
> solutions may \
> not be found.
>
> Out[3]=
> {{\[Psi] -> Pi/6, \[Theta] -> Pi/4, \[Phi] -> Pi/3}}
>
> However, I noticed that if instead of exact rotations being entered, nume=
rical approximations are entered:
>
> In[4]:=
> A=RotationMatrix3D[Pi/3.,Pi/4.,Pi/6.];
>
> then solve no longer finds the solution...
>
> In[5]:=
> Solve[RotationMatrix3D[=CF=95,=CE=B8,=CF=88]\[Equal]A,{=CF=95,=CE=B8,=CF=
=88}]
>
> Out[5]=
> {}
>
> my problem is that i have a rotation matrix
>
> {{0.977431, 0.158491, 0.139673}, {-0.0822761,
>   0.894559, -0.439311}, {-0.194572, 0.417905, 0.88741}}
>
> and i really want to find the rotations that are described by this matrix=
, either in Euler angles (for mathematica vs 5.2), or (preferably) in xyz (=
pitch-roll-yaw) convention (for mathematica vs 6). I am sorry if this is a =
very simple problem, but i don't know much about matrix maths...
>