Home >>C Math Functions >C math atan2() function

C math atan2() function

C math atan2() function

The C library function double atan2(double y, double x) is used to return the arc tangent in radians of y/x based on the signs of both values to determine the correct quadrant. It takes two arguments: x-coordinate and y-coordinate, and calculate the angle in radians for the quadrant. This function is defined in <math.h> header file.

Syntax:
double atan2(double y, double x);

Parameters:

  • x − It is the floating point value representing an x-coordinate
  • y − It is the floating point value representing a y-coordinate.
Here is an example of atan2() function:

#include <stdio.h>
#include <math.h>
#define PI 3.14159265 
int main () 
{ 
double x, y, ret, val; 
x = 0.75;
y = 0.555;  
val = 180.0 / PI; 
ret = atan2(y,x) * val; 
printf("The arc tangent of x = %lf, y = %lf  is %lf", x, y,ret); 
return(0); 
}

Output:
The arc tangent of x = 0.750000, y = 0.555000 is 36.501441
Example-2

#include <stdio.h>
#include <math.h>
#define PI 3.14159265 
int main () 
{ 
double x, y, ret, val; 
x = 0.75;
y = -0.555;  
val = 180.0 / PI; 
ret = atan2(y,x) * val; 
printf("The arc tangent of x = %lf, y = %lf  is %lf", x, y,ret); 
return(0); 
}

Output:
The arc tangent of x = 0.750000, y = -0.555000 is -36.501441