c - 为什么我必须声明常量 Pi 值才能在 Math.h 中使用 Cos 函数?

标签 c math degrees trigonometry radians

x = 60.0;
val = PI / 180.0;
ret = cos( x*val );
printf("The cosine of %lf is %lf degrees\n", x, ret);

您好,我在自学 math.h 中的函数,然后我尝试使用 COS 函数在程序中求半径的余弦值。我试图找到这个函数的解释,为什么 COS 函数需要在 Cos 函数中添加 Pi/180.0 才能正确计算半径的 cos。非常感谢你

最佳答案

如果您检查 documentation ,您会看到 cos() 接受以弧度为单位的角度,而不是度数。将 60 度角乘以 PI/180.0,即可将其转换为弧度。

关于c - 为什么我必须声明常量 Pi 值才能在 Math.h 中使用 Cos 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47104840/

相关文章:

正确的 sscanf() 原型(prototype), "int sscanf ( const char * s,const char * format, ...);"或 int sscanf (char * s,const char * format, ...);?

c# - 度数计算不准确

javascript - 使用html5 canvas在圆形中以不同 Angular 显示不同值

c - "main"地址的功能保持不变。为什么局部变量地址每次运行都会改变?

c++ - GetProcessAffinityMask 返回空进程关联

c - malloc,免费 : error invalid next size(fast)

javascript - 尝试制作一排随机宽度与 Canvas 宽度成比例的砖 block

java - 在Java深度生成列表n层的所有组合

javascript - 我为什么要使用 Math.imul()?

maxima - 多项式最大值的系数