atan2 - C math.h

C examples for math.h:atan2

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Compute arc tangent with two parameters

Prototype

long double atan2l(long double y, long double x);
long double atan2(long double y, long double x);
     double atan2(double y, double x);
      float atan2f(float y, float x);
      float atan2(float y, float x);
     double atan2(Type1 y, Type2 x);       

Parameters

Parameter Description
y Value representing the proportion of the y-coordinate.
x Value representing the proportion of the x-coordinate.

If both arguments passed are zero, a domain error occurs.

Return Value

Principal arc tangent of y/x, in the interval [-pi,+pi] radians. One radian is equivalent to 180/PI degrees.

Example

Demo Code


#include <stdio.h>
#include <math.h> /* atan2 */

#define PI 3.14159265/*from   w w  w. ja v  a2s  . co  m*/

int main ()
{
  double x = -10.0;
  double y = 6.0;
  double result = atan2 (y,x) * 180 / PI;
  printf ("The arc tangent for (x=%f, y=%f) is %f degrees\n", x, y, result );
  return 0;
}

Related Tutorials