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.

y and x
Values from whose division has to be calculated the arctangent.
i.e.: Coordinates for the vector whose angle is to be calculated.

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


© The C++ Resources Network, 2000