1

I use the following code to convert a 3X3 rotation matrix to angles :

(_r = double[9] )

double angleZ=atan2(_r[3], _r[4])* (float) (180.0 / CV_PI);
double angleX=180-asin(-1*_r[5])* (float) (180.0 / CV_PI);
double angleY=180-atan2(_r[2],_r[8])* (float) (180.0 / CV_PI);

here is a little helper

_r[0] _r[1] _r[2]
_r[3] _r[4] _r[5]
_r[6] _r[7] _r[8]

does this make any sense ? cause the angles seem too... interdependent ? x y z all react to single pose change...

the rotation matrix is received from opencv cvPOSIT function so the points of interest might be wrong and giving this confusing effect ...

but somehow i think im just doing the conversion wrong :)

I am applying the angles in opengl to a cube :

glRotatef(angleX,1.0f,0.0f,0.0f);
glRotatef(angleY,0.0f,1.0f,0.0f);
glRotatef(angleZ,0.0f,0.0f,1.0f);
n00b
  • 5,642
  • 2
  • 30
  • 48
  • 1
    Perhaps this could be usefull: http://www.soi.city.ac.uk/~sbbh653/publications/euler.pdf – SleuthEye Aug 25 '14 at 15:42
  • ahh more greek letters and matrices :D – n00b Aug 25 '14 at 15:45
  • There are many conventions for euler angles; if you don't tell us which one you are using, it's hard to even check if your formula is right. One of the reasons to avoid them altogether; see http://en.wikipedia.org/wiki/Euler_angles – DanielKO Aug 25 '14 at 15:52
  • I am trying to use it in opengl glRotatef - updated answer – n00b Aug 25 '14 at 15:56

1 Answers1

5

What you are trying to accomplish is not as easy as you might think. There are multiple conventions as to what the euler angles are called (x,y,z,alpha,beta,gamma,yaw,pitch,roll,heading,elevation,bank,...) and in which order they need to be applied.

The are also some problems with ambiguities in certain positions, see Wikpedia article on Gimbal Lock.

Please read the Euler Angle Formulas document by David Eberly. Its very useful and includes a lot of formulas for various conventions and you probably should base your code on them if you want to have stable formulas even in the corner cases.

oxygene
  • 621
  • 4
  • 14
  • this one has pseudo code but i feel like i already tried that.. but 1+ and ill try again. too bad i suck at maths – n00b Aug 25 '14 at 15:55
  • 1
    even though im using my own formula since it also works (imho even better) i accept this cause this pdf is a great resource for anyone looking for the answer ;) – n00b Aug 26 '14 at 12:39