Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to get the axis angle from a matrix of the form:

$$ \begin{matrix} \cos \theta & -\sin \theta & tx\\ \sin \theta & \cos \theta & ty\\ 0 & 0 & 1\\ \end{matrix} $$

Into an axis angle. I've tried the standard formula:

$\theta$ = $\arccos$ ( (m[0][0] + m[1][1] + m[2][2] - 1) / 2 )

However this formula inverts when the angle reaches PI. For example, given a rotational matrix for an angle of 225 degrees, we get a returned value of about 135 degrees, which in itself is perfectly correct, but I really need the full value.

Is there any way of handling these cases?

share|cite|improve this question
up vote 0 down vote accepted

You may have an Atan2 function available, which sorts out the quadrants. If so, you want Atan2$(\cos\theta,\sin\theta)$ Otherwise, you can do $\arccos\theta$ but then you have to sort out the quadrants afterward using the value for $\sin\theta$

share|cite|improve this answer
So the angle would be atan2(m[0][0],m[1][0])? – Ben Feb 11 '11 at 15:57
Thanks for the help Ross, I ended up using the arccos approach and made it adjust the quadrant when sin theta is negative. Works fine now! – Ben Feb 11 '11 at 16:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.