最重要的几条:
- C++中sin、cos、tan、asin、acos、atan等三角函数的输入是弧度,而不是角度
注意tan、atan等函数不能接受整数,tan(45)会报错“error C2668: 'tan' : ambiguous call to overloaded function”
弧度和角度的转换:
- 角度 45度-》弧度 45*PI/180
- 弧度值转角度 弧度值 * 180/PI
-----------------------------------------------------------------------------------------------------------------------------------------------------------
来源于原文的代码,写在这里是只是为了更加方便一些
#include <iostream>
#include <cmath>
using namespace std;
#define PI 3.1415926
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;
}