In C the atan2 function has the following signature:
double atan2( double y, double x );
Other languages do this as well. This is the only function I know of that takes its arguments in Y,X order rather than X,Y order, and it screws me up regularly because when I think coordinates, I think (X,Y).
Does anyone know why atan2's argument order convention is this way?
atan2(y,x) is generally used if you want to convert cartesian coordinates to polar coordinates. It will give you the angle, while sqrt(x*x+y*y) or, if available, hypot(y,x) will give you the size. atan(x) is simply the inverse of tan.
atan2() function returns the angle in the plane (in radians) between the positive x-axis and the ray from (0,0) to the point (x,y), for Math. atan2(y,x) .
ATAN2(y,x) returns the arc tangent of the two numbers x and y. It is similar to calculating the arc tangent of y / x, except that the signs of both arguments are used to determine the quadrant of the result. The result is an angle expressed in radians. To convert from radians to degrees, use the DEGREES function.
The four-quadrant inverse tangent, atan2(Y,X) , returns values in the closed interval [-pi,pi] based on the values of Y and X , as shown in the graphic. In contrast, atan(Y/X) returns results that are limited to the interval [-pi/2,pi/2] , shown on the right side of the diagram.
Because I believe it is related to arctan(y/x), so y appears on top.
Here's a nice link talking about it a bit: Angles and Directions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With