cMath和sin函数的问题

problems with cMath and the sin function

本文关键字:问题 函数 sin cMath      更新时间:2023-10-16

嘿,我正在做一些图形数学运算,并将我认为是浮点的东西(我很确定我事先操作浮点的方式会以某种方式弄乱一些东西…)插入函数中,然后得到奇怪的负结果。

例如,当执行以下操作时,当角度最初等于350.0时,测试结果为
-.99.为什么

Angle= (float)(Angle-(int)Angle)+(float)((int)Angle%90); 
// calculates x and y based on angle and Hypotenuse
float test= sin(Angle);
float test2= 1/(Speed*Time);
float test3= test/test2;
buffX= sin(Angle)/ (1.f/(Speed*Time));
buffY= sin(Angle-90)/ (1.f/(Speed*Time));

试图通过在一切都不起作用之前放置(float)来保持Angle的浮动。。。请帮忙谢谢

这是因为C/C++运行时函数sin()需要的参数是弧度,而不是度数。

使用转换为弧度

float test= sin(Angle / 180 * M_PI);

等等。

sin的参数是弧度,而不是度数。你需要把你的数字乘以π/180