C++中的sin、cos、tan、asin、acos、atan等函数输入的都是弧度,注意应将角度转化为弧度后进行运算
一周是360度,也是2π弧度,即360°=2π 所以弧度 = 角度 * PI / 180.0
三角函数
- double sin(double)
- double cos(double)
- double tan(double)
代码演示
#include <stdio.h>
#include <math.h>
#define PI 3.1415926
int main(void)
{
double a;
while(~scanf("%lf", &a))
{
printf("sin = %.2f\ncos = %.2f\ntan = %.2f\n", sin(a*PI/180.0), cos(a*PI/180.0), tan(a*PI/180.0));
}
return 0;
}

反三角函数
反三角函数计算结果为弧度,可将弧度转化为角度
- double asin(double) 结果介于[-PI/2, PI/2]
- double acos(double) 结果介于[-PI, PI]
- double atan(double) 结果介于[-PI/2, PI/2]
- double atan2(double y, double x) 结果介于[-PI, PI]
atan2函数的使用第一个参数设为y点坐标,第二个参数为x点坐标,所得结果为弧度
代码演示
#include <stdio.h>
#include <math.h>
#define PI 3.1415926
int main(void)
{
double a;
while(~scanf("%lf", &a))
{
printf("asin = %.2f\nacos = %.2f\natan = %.2f\n", asin(a)*180.0/PI, acos(a)*180.0/PI, atan(a)*180.0/PI);
double x, y;
scanf("%lf%lf", &x, &y);
printf("atan2 = %.2f\n", atan2(y, x)*180.0/PI);
}
return 0;
}

1万+



被折叠的 条评论
为什么被折叠?



