atan2
double atan2 ( double y, double x ); | math.h |
cplusplus.com |
Calculate arctangent, 2 parameters.
Performs the trigonometric arctangent operation on y/x and returns an
angle in the range from -PI to PI expressed in radians, using
the signs of the parameters to determine the quadrant.
The result is valid even if x is 0
(angle is PI/2 or -PI/2).
In fact this function returns the angle of bidimensional vector (x,y).
Parameters.
Return Value.
Arctangent of y/x.
Portability.
Defined in ANSI-C.
ANSI-C++ adds float and double overloaded versions of this function,
with the same bahavior but being both, parameter and result, of one of these types.
Example.
/* atan2 example */
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
main ()
{
double x, y, result;
x = 0;
y = 5;
result = atan2 (y,x) * 180 / PI;
printf ("Arctangent for (x=%lf, y=%lf) is %lf degrees\n", x, y, result );
return 0;
}
Output:
Arctangent for (x=0.000000, y=5.000000) is 90.000000 degrees
See also.
atan,
acos,
asin,
cos,
sin,
tan