📅  最后修改于: 2020-09-25 07:23:49             🧑  作者: Mango
此函数在
[Mathematics] tan-1(y/x) = atan2(y, x) [In C++ Programming]
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); // For combinations of arithmetic types.
函数 atan2()带有两个参数:x坐标和y坐标。
atan2() 函数返回[-π,π]范围内的值。如果x
和y
均为零,则atan2() 函数将返回0。
#include
#include
using namespace std;
int main()
{
double x = 10.0, y = -10.0, result;
result = atan2(y, x);
cout << "atan2(y/x) = " << result << " radians" << endl;
cout << "atan2(y/x) = " << result*180/3.141592 << " degrees" << endl;
return 0;
}
运行该程序时,输出为:
atan2(y/x) = -0.785398 radians
atan2(y/x) = -45 degrees
#include
#include
#define PI 3.141592654
using namespace std;
int main()
{
double result;
float x = -31.6;
int y = 3;
result = atan2(y, x);
cout << "atan2(y/x) = " << result << " radians" << endl;
// Display result in degrees
cout << "atan2(y/x) = " << result*180/PI << " degrees";
return 0;
}
运行该程序时,输出为:
atan2(y/x) = 3.04694 radians
atan2(y/x) = 174.577 degrees