Assuming I have a 2D rotation matrix:
cos(t) -sin(t) 0
sin(t) cos(t) 0
0 0 1
How do you retrieve the correct rotation angle?
If you use acos on the first element, you only get values between 0 and pi. The question is what do you do if t is smaller than 0 (of course I do not know t 😉 )?
The function
atan2()in most C-family programming languages takes both a y and x value and computes the arctangent of the ratio between them, taking into account the sign of both terms to give the correct full-circle angle.atan2( sin(t), cos(t) )returns (approximately)tin the range (-pi,+pi].