C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Math atan2()

C++ Math atan2()

该函数查找坐标的反正切。
假设坐标为(x,y):
atan2(y,x) = tan-1(y/x); 

语法

假设坐标为(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的值均为零,则返回零值
如果任何参数为整数类型,则将其强制转换为double。 如果任何参数为long double类型,则将其强制转换为long double。

示例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()计算逆切线。

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

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4