       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:= m = {{0.977431, 0.158491, 0.139673}, {-0.0822761,
0.894559, -0.439311}, {-0.194572, 0.417905, 0.88741}};

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

Out= 1.38282*10^-6

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

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

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

Out= {{1,0,0},{0,1,0},{0,0,1}}

Now to how to find angles:

Observe that

In:= sm[[2, 2]]

Out= Cos[\[Theta]]

Thus

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

Out= 0.463353

Also

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

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

and thus we find another angle:

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

Out= 4.52725

And, finally,

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

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

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

Out= 1.93329

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

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

Out= 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:=
> Needs["Geometry`Rotations`"]
>
> In:=
> B=RotationMatrix3D[Pi/3,Pi/4,Pi/6];
>
> In:=
> Solve[RotationMatrix3D[=CF=95,=CE=B8,=CF=88]\[Equal]B,{=CF=95,=CE=B8,=CF=
=88}]
>
>  From In:=
> Solve::ifun: Inverse functions are being used by Solve, so some
> solutions may \
> not be found.
>
> Out=
> {{\[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:=
> A=RotationMatrix3D[Pi/3.,Pi/4.,Pi/6.];
>
> then solve no longer finds the solution...
>
> In:=
> Solve[RotationMatrix3D[=CF=95,=CE=B8,=CF=88]\[Equal]A,{=CF=95,=CE=B8,=CF=
=88}]
>
> Out=
> {}
>
> 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...
>