atan2(x,y)函数详解

首页 / C++入门教程 / atan2(x,y)函数详解

函数查找坐标的反正切。

假设坐标为(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的值均为零,则返回零值。

链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-atan2-function.html

来源:LearnFk无涯教程网

  • 如果任何参数为整数类型,则将其强制转换为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)<<'\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()计算逆切线。

无涯教程网

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)<<'\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()函数可找到切线的逆。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

推荐系统三十六式 -〔刑无刀〕

微服务架构实战160讲 -〔杨波〕

浏览器工作原理与实践 -〔李兵〕

摄影入门课 -〔小麥〕

人人都能学会的编程入门课 -〔胡光〕

自动化测试高手课 -〔柳胜〕

现代React Web开发实战 -〔宋一玮〕

手把手带你写一个MiniSpring -〔郭屹〕

结构沟通力 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)