函数查找坐标的反正切。
假设坐标为(x,y):
假设坐标为(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 );
y :代表y坐标值。
x :它表示x坐标值。
它返回范围为[-?,?]的值,如果x和y的值均为零,则返回零值。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-atan2-function.html
来源:LearnFk无涯教程网
让我们看一个简单的示例,其中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)<<'\n'; 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()计算逆切线。
让我们看一个简单的示例,其中" 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)<<'\n'; 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()函数可找到切线的逆。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)