提示:atan()和atan2()为基于<cmath>(math.h)头文件的计算函数,可用于角度归一化。
一、atan()函数
1.输入要求
double atan (double x);
float atan (float x);
long double atan (long double x);
double atan (T x); // additional overloads for integral types
2.输出范围
atan(x)函数返回以弧度为单位的角度,范围为[-pi/2,+pi/2],包含-pi/2和+pi/2的。由此可以看出,atan(x)函数只能区分一象限和四象限的点。取一象限和三象限任意一点Ai(ai,bi)计算x=bi/ai,x均为正值。对于二象限和四象限则均为负值。
3.example
输出值为45
/* atan example */
#include <stdio.h> /* printf */
#include <math.h> /* atan */
#define PI 3.14159265
int main ()
{
double param, result;
param = 1.0;
result = atan (param) * 180 / PI;
printf ("The arc tangent of %f is %f degrees\n", param, result );
return 0;
}
二、atan2()函数
1.输入要求
double atan2 (double y , double x);
float atan2 (float y , float x);
long double atan2 (long double y , long double x);
double atan2 (Type1 y , Type2 x); // additional overloads
2.输出范围
atan2(x)函数返回以弧度为单位的角度,范围为[-pi,+pi],包含-pi和+pi的。函数内部考虑了参数x,y 的符号。所以可以区分坐标点在哪个象限。
3.example
输出值为135
/* atan example */
#include <stdio.h> /* printf */
#include <math.h> /* atan */
#define PI 3.14159265
int main ()
{
double param, result;
param = 1.0;
result = atan (param) * 180 / PI;
printf ("The arc tangent of %f is %f degrees\n", param, result );
return 0;
}
参考链接
cplusplus.com/reference/cmath/atan/