MATLAB Answers

0

Why doesn't atan2 (u,v) give me the right angle of two simple vectors?

Asked by farzad on 4 Jun 2019
Latest activity Edited by Jan
on 28 Jun 2019
Accepted Answer by Jan
Hi All
I was using the atan2(u,v) to calculate the angles between vectors, untill I checked it for
u=[0,0,0]
v= [1,1,1]
doing :
teta=atan2(norm(cross(u,v)),dot(u,v));
I get teta = 0
I am expecting teta = 54 °
where am I going wrong ?

  1 Comment

Why do you expect it to be 54? IT is showing correct.
teta=atan2d(norm(cross(u,v)),dot(u,v));

Sign in to comment.

1 Answer

Answer by Jan
on 4 Jun 2019
Edited by Jan
on 4 Jun 2019
 Accepted Answer

Of course this code replies 0. If one of the vectors is the Null vector, there cannot be an angle different from 0.
So the only problem is that you expect 54°. atan2 will not reply degrees at all, but radians.
u = [1, 0, 0]
v = [cos(0.123), -sin(0.123), 0]
atan2(norm(cross(u,v)),dot(u,v))
>> 0.1230 % As expected

  1 Comment

FYI if you want degrees you can use the atan2d function.

Sign in to comment.