gpt4 book ai didi

c++ - cMath 和 sin 函数的问题

转载 作者:行者123 更新时间:2023-11-30 01:29:09 24 4
gpt4 key购买 nike

嘿,所以我正在做一些图形数学并插入我认为是 float 的东西(我很确定我事先操纵 float 的方式不知何故搞砸了 ...)进入功能并得到奇怪的负面结果。

例如当 Angle 初始等于 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 float ...请帮忙! 谢谢!

最佳答案

那是因为 C/C++ 运行时函数 sin() 需要以弧度而不是度数为单位的参数。

转换为弧度:

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

等等

关于c++ - cMath 和 sin 函数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6368055/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com