函数查找坐标的反正切。
假设坐标为(x,y):
atan2(y,x) = tan-1(y/x);
atan2 - 语法
假设坐标为(x,y)。语法为:
float atan2(float y, float x); double atan2(double y, double x); long double atan2(long double y, long double x); Promoted atan2(Arithmetic1 y, Arithmetic x );
atan2 - 参数
y :代表y坐标值。
x :它表示x坐标值。
atan2 - 返回值
它返回范围为[-?,?]的值,如果x和y的值均为零,则返回零值。
- 如果任何参数为整数类型,则将其强制转换为double。
- 如果任何参数为long double类型,则将其强制转换为long double。
atan2 - 例子1
让我们看一个简单的示例,其中x和y均为零。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x=0;
int y=0;
cout<<"Value of tan(y/x) is : "<<tan(y/x)<<
;
std::cout << "Value of tan-1(y/x) is : " <<atan2(y,x)<< std::endl;
return 0;
}
输出:
Value of tan(y/x) is : 0 Value of tan-1(y/x) is : 0
在此示例中,当" x"和" y"均为零时,atan2()计算逆切线。
atan2 - 例子2
让我们看一个简单的示例,其中" x"和" y"都是不同的类型。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x=6;
float y=7.8;
cout<<"Value of tan(y/x) is : "<<tan(y/x)<<
;
std::cout << "Value of tan-1(y/x) is : " <<atan2(y,x)<< std::endl;
return 0;
}
输出:
Value of tan(y/x) is : 3.6021 Value of tan1(y/x) is : 0.915101
在此示例中,当x为整数类型且y为浮点类型时,atan2()函数可找到切线的逆。