what is the difference between atan and atan2 in c++ ?
-
atan2allows calculating the arctangent of all four quadrants.atanonly allows calculating from, if I remember right, quadrants 1 and 4. -
With atan2 you can determine the quadrant as stated here.
You can use atan2 if you need to determine the quadrant.
-
http://en.wikipedia.org/wiki/Atan2
endian : 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.xan : Fair enough. I didn't know the answer myself, but I hoped the link might provide useful information for the asker. -
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.
yesraaj : atan2(x,y) -> atan2(y,x)Roman M : fixed. For future lazy questions I recommend cplusplus.com -
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.
0 comments:
Post a Comment