反三角函数的范围:
acos:[0,π]的弧度范围内
asin:[-π/2,π/2]的弧度范围内
atan:[-π/2,π/2]的胡度范围内
弧度转角度,需要乘以(PI/180.0)
注意:最好是
代码:
#include <iostream>
#include <cmath>
using namespace std;
//#define PI 3.1415926
const double PI=acos(-1.0);
int main()
{
//注意tan、atan等函数不能接受整数,tan(45)会报错“error C2668: 'tan' : ambiguous call to overloaded function”
float tanValue1 = tan(45.0f);
float tanValue2 = tan(45*PI/180.0f);
cout<<"tan(45) = "<<tanValue1<<endl;
cout<<"tan(45*PI/180) = "<<tanValue2<<endl;
cout<<"可以看出:tan函数输入的是弧度! 如果想对角度进行tan运算,需要乘以(PI/180)把角度转为弧度。"<<endl<<endl;
float atanValue1 = atan(1.0f);
float atanValue2 = atan(1.0f)*180.0f/PI;
cout<<"atan(1) = "<<atanValue1<<endl;
cout<<"(atan(1.0))*180/PI = "<<atanValue2<<endl;
cout<<"可以看出:atan函数输出的是弧度! 如果想进行atan运算得到角度,需要乘以(180/PI)把弧度转为角度"<<endl<<endl;
cin.get();
return 0;
}
运行结果:
结论:
C++中sin、cos、tan、asin、acos、atan等三角函数的输入是弧度,而不是角度。
如果想对角度进行这些三角函数运算,需要乘以(PI/180)把弧度转为角度。