Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get rotation from 2d transformation matrix

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 ;) )?

like image 608
user765269 Avatar asked Dec 17 '25 18:12

user765269


1 Answers

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) t in the range (-pi,+pi].

like image 101
Russell Borogove Avatar answered Dec 20 '25 01:12

Russell Borogove



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!