rotation angles from rotation matrix

Discussion in 'Mathematica' started by will, Aug 11, 2007.

  1. will

    will Guest

    Dear Math forum,

    I found some useful code for retrieving the Euler angles of a rotation from a rotation matrix; see

    which goes as follows:




    From In[3]:=
    Solve::ifun: Inverse functions are being used by Solve, so some
    solutions may \
    not be found.

    {{\[Psi] -> Pi/6, \[Theta] -> Pi/4, \[Phi] -> Pi/3}}

    However, I noticed that if instead of exact rotations being entered, numerical approximations are entered:


    then solve no longer finds the solution...



    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...

    Thank you in advance for your help,

    will, Aug 11, 2007
    1. Advertisements

  2. will

    sashap Guest

    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]]


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

    Out[43]= 0.463353


    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

    rical approximations are entered:
    , 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...
    sashap, Aug 12, 2007
    1. Advertisements

  3. will

    rob Guest

    I gather all this is for V6; there is no RotationMatrix
    function available on my 5.1 system. (RotationMatrix3D is
    there though).

    Either way it appears that using RotationMatrix3D to work
    with Euler angles doesn't work in the real world.
    rob, Aug 13, 2007
  4. will

    sashap Guest

    Yes, RotationMatrix is new in version 6.
    Rather, it does work in the real world, one just needs to properly
    apply it.

    Oleksandr Pavlyk
    Wolfram Research
    sashap, Aug 14, 2007
  5. will

    rob Guest

    OK, sure.
    rob, Aug 16, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.