计算正确的音高
public double GetPitchToFace(double Z2, double Z1, double X2, double X1)
{
double Arc;
Arc = Math.Atan2(Z2 - Z1, X2 - X1);
return Arc;
}
我正在尝试制定正确的音高,以“面对”特定点。
使用AtAN2(如上所述)似乎返回了正确的值,但是游戏中的音高系统似乎很奇怪。
与其将逆时针从0 radian持续到6.2,它从0开始到3雷达,然后跳到-3雷迪安,然后再次回到0。
希望您能理解上面的不良示例。
我需要一种从奇怪的音高 /径向系统转换为标准0-6.2弧度以返回正确的音高的方法。
谢谢。
public double GetPitchToFace(double Z2, double Z1, double X2, double X1)
{
double Arc;
Arc = Math.Atan2(Z2 - Z1, X2 - X1);
return Arc;
}
I am attempting to work out the correct pitch in order to "face" a specific point.
Using Atan2 (as seen above) seems to return the correct values however in-game the pitch system seems to work rather strangely.
Instead of increasing anti-clockwise from 0 radian all the way back to 6.2 it starts from 0 up to 3 radian then jumps down to -3 radian and works its way back to 0 once again.
Hopefully you can understand the bad drawing example above.
I need a way to convert from that strange pitch / radian system to the standard 0 - 6.2 radians in order to return a correct pitch.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
MATH.ATAN2
方法返回角度θ(在弧度中),因此,当-π≤θ≤π时,它将产生负值。输入点位于第三或第四象限。要仅返回正值(IE 0≤θ≤2π),可以使用简单的数学。由于2π是一个完整的旋转,因此可以添加每当
Math.atan2
方法返回负值时,可以添加。这只会为您提供所需范围的价值。Since the
Math.Atan2
method returns the angle θ (in radians) such that -π ≤ θ ≤ π it will yield negative values when the input point is in the third or fourth quadrant.To return only positive values (i.e. 0 ≤ θ ≤ 2π) one can use simple mathematics. Since 2π is a full rotation you can add that whenever the
Math.Atan2
method returns a negative value. This will only give you values in your wanted range.