C++调用三角函数库之前,需要引入头文件#include<cmath>.
#include<iostream>
#include<cmath>
using namespace std;
#define PI 3.1415926535898
int main()
{
float x;
float y;
x = sin(30*(PI/180));
y = cos(60 * (PI / 180));
cout << x << endl;
cout << y << endl;
}
调用三角函数时,需要将角度转化为弧度。
常用函数:
abs 绝对值函数
sin 正弦函数
cos 余弦函数
tan 正切函数
asin 反正弦函数
acos 反余弦函数
atan 反正切函数
exp e的次方
pow 次幂
sqrt 开方
版权声明:本文为m0_64182150原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。