user765269
user765269

Reputation: 423

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

Upvotes: 3

Views: 3253

Answers (2)

Russell Borogove
Russell Borogove

Reputation: 19037

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].

Upvotes: 3

acs
acs

Reputation: 2259

There are an infinite number of t that can satisfy the solution (t + 2*pi()*n) for integer n. If you use acos(cos(t)) you'll get the result between 0 and pi, but if you also check asin(sin(t)) you will be able to figure out whether the rotation was clockwise or counterclockwise.

Upvotes: 1

Related Questions