What is atan2 in c programming?
atan2 in c is used to find arc tangent in radians of y/x based on signs of both values that determine the correct quadrant.
It is defined in math.h header file.
Prototype
double atan2(double y, double x);
Parameter
This function takes two floating point values as x and y co-ordinate values.
Return value
This function returns arc tangent of y/x ,in the interval [-pi,+pi] radians.
Example program for atan2 in c
#include<stdio.h>
#include<math.h>
#define PI 3.14
int main()
{
double x=4.0,y=5.0,res,val;
val=180.0/PI;
res=atan2(y,x)*val;
printf("The arc tangent value is %lf \n",res);
return 0;
}
While using gcc use below command to add math header.
gcc file_name.c -lm
Code explanation
atan2 function is called by passing x and y values to it. The result is multiplied to get the arc tangent value in radians. The result is printed onto the console.
Difference between atan2 and atan in c
atan2 in c is used to find arc tangent in radians of y/x based on signs of both values that determine the correct quadrant. atan in c is a mathematical function that is used to find the arc tangent value of a given number in radians.
atan2 takes two input parameters as x and y co-ordinates. atan takes one input parameter.
Prototypes are as follows
double atan2(double y, double x);
double atan(double y);
atan2( ) | atan( ) |
Used to find arc tangent in radians of y/x based on signs of both values. | Used to find arc tangent of a given number. |
double atan2(double y, double x); | double atan(double y); |
People also ask for
What is the difference between atan2 and tan in c?
atan2 in c is used to find arc tangent in radians of y/x based on signs of both values that determine the correct quadrant. tan in c is a mathematical function that is used to find the tangent of a given number.
What is the difference between atan2 and tanh in c?
atan2 in c is used to find arc tangent in radians of y/x based on signs of both values that determine the correct quadrant. tanh in c is used to find the hyperbolic tangent of a given number.