Frank-Rene Schäfer
Frank-Rene Schäfer

Reputation: 3352

Python: Rotation Matrix to Angles

Given a rotation matrix

     | r00  r01  r02 |
 R = | r10  r11  r12 |
     | r20  r21  r22 |

and an specific rotation sequence 'abc' where a, b, c are taken from 'XYZ'. Is there a general solution (for an arbitrary rotation sequence) available in Python to translate the rotation matrix into rotation angles around X, Y, and Z axis?

Upvotes: 2

Views: 2403

Answers (1)

Frank-Rene Schäfer
Frank-Rene Schäfer

Reputation: 3352

It seems every rotation sequence has its separate solution. Given a sequence "ZYX" the resulting symbolic expression for the rotation matrix is

       |      Cy Cz              -Cy Sz             Sy  |
Rxyz = │  Sx Sy Cz + Cx Sz   -Sx Sy Sz + Cx Cz   -Sx Cy │
       | -Cx Sy Cz + Sx Sz    Cx Sy Sz + Sx Cz    Cx Cy |

with C and S for cosine and sine. x, y, z indices note the rotation around x, y, and z axis. From that, a set of equations may be derived, namely:

           Cy Cz = r00
         - Cy Sz = r01
         - Sx Cy = r02
Sx Sy Cz + Cx Sz = r10
      ...

Those need to be resolved for at least one angle expression for each axis. Then, 'arcsin' or 'arccos' is applied to get the real angle. It seems that the symbolic math needs to be performed for each sequence separately.

Upvotes: 2

Related Questions