tags:

views:

2312

answers:

5

what is the difference between atan and atan2 in c++ ?

+4  A: 

atan2 allows calculating the arctangent of all four quadrants. atan only allows calculating from, if I remember right, quadrants 1 and 4.

Chris Jester-Young
+1  A: 

With atan2 you can determine the quadrant as stated here.

You can use atan2 if you need to determine the quadrant.

Burkhard
A: 

http://en.wikipedia.org/wiki/Atan2

xan
I really disagree with this blind posting of Wikipedia links. The point of SO is to encourage communication between programmers, and for other programmers to be able to benefit from the questions asked. I will now know if I need it in the future, that atan and atan2 exist, and what the diffs are.
endian
Fair enough. I didn't know the answer myself, but I hoped the link might provide useful information for the asker.
xan
+1  A: 

atan(x) Returns the principal value of the arc tangent of x, expressed in radians.

atan2(y,x) Returns the principal value of the arc tangent of y/x, expressed in radians.

Notice that because of the sign ambiguity, a function cannot determine with certainty in which quadrant the angle falls only by its tangent value (atan alone). You can use atan2 if you need to determine the quadrant.

Roman M
atan2(x,y) -> atan2(y,x)
yesraaj
fixed. For future lazy questions I recommend cplusplus.com
Roman M
+2  A: 

Another thing to mention is that atan2 is more stable when computing tangents using an expression like atan(y/x) and x is 0 or close to 0.

Laserallan