【发布时间】:2016-08-12 12:12:37
【问题描述】:
由于 PS3 3.40 SDK 引起的某些编译器问题,我无法使用 c++ 函数 sin() 和 cos()。 sin() & cos() 的计算是什么,所以我可以在不需要 math.h 的情况下使用函数?
到目前为止,我已经想出了这些,但它们似乎无法正常工作?
float sin(float deg) {
bool neg = false;
while (deg >= 360) deg = deg - 360;
while (deg < 0) deg = deg + 360;
if (deg > 180) {
deg = deg - 180;
neg = true;
}
float ret = (float)(4*deg*(180-deg))/(40500-(deg*(180-deg)));
if (neg)return ret*-1;
return ret;
}
float cos(float AnglesDeg)
{
float AnglesRad = DegreesToRadians(AnglesDeg);
float Rad = (float)(PI/2.0f)-AnglesRad;
float ang = RadiansToDegrees(Rad);
return sin(ang);
}
【问题讨论】:
-
由于某些编译器问题,我无法使用 c++ 函数 sin() 和 cos()。 那些“编译器问题”是什么?
-
可以加入
cmath吗? -
sin()和cos()是 stdlib 的一部分,因此您应该可以使用它们,请尝试修复编译错误,如果不能,然后将它们添加到您的问题中在这方面寻求帮助。 -
也许你应该自己实现一些泰勒级数函数。
-
@Jaa-c 标准的
cos和sin函数当然不是微不足道的,你不能简单地从头文件中复制它们。
标签: c++ math trigonometry