计算正确的音高

发布于 2025-01-27 08:48:36 字数 594 浏览 2 评论 0原文

        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.

Example of Pitch

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初见你 2025-02-03 08:48:36

由于MATH.ATAN2方法返回角度θ(在弧度中),因此,当-π≤θ≤π时,它将产生负值。输入点位于第三或第四象限。

要仅返回正值(IE 0≤θ≤2π),可以使用简单的数学。由于是一个完整的旋转,因此可以添加每当Math.atan2方法返回负值时,可以添加。这只会为您提供所需范围的价值。

 public double GetPitchToFace(double Z2, double Z1, double X2, double X1)
    {            
        double Arc;
        double theta = Math.Atan2(Z2 - Z1, X2 - X1);
        Arc = (theta >= 0) ? theta : (2*Math.PI + theta);
        return Arc;
    }

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 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.

 public double GetPitchToFace(double Z2, double Z1, double X2, double X1)
    {            
        double Arc;
        double theta = Math.Atan2(Z2 - Z1, X2 - X1);
        Arc = (theta >= 0) ? theta : (2*Math.PI + theta);
        return Arc;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文