射弹击中其路径顶点的坐标

发布于 2024-09-09 06:52:57 字数 359 浏览 5 评论 0原文

我有一个射弹,我想通过其路径顶点的特定坐标。我一直在使用 giogadi 概述的一个极好的方程这里< /a>,通过将其产生的速度值插入到chipmunk的cpBodyApplyImpulse函数中。

该方程有一个我无法弄清楚的缺点。仅当我想要击中的坐标的 y 值高于大炮(我的射弹开始的位置)时,它才有效。这意味着我不能以向下的角度拍摄。

任何人都可以帮我找到一个合适的方程,无论目标与大炮的关系如何,该方程都有效吗?

I have a projectile that I would like to pass through specific coordinates at the apex of its path. I have been using a superb equation that giogadi outlined here, by plugging in the velocity values it produces into chipmunk's cpBodyApplyImpulse function.

The equation has one drawback that I haven't been able to figure out. It only works when the coordinates that I want to hit have a y value higher than the cannon (where my projectile starts). This means that I can't shoot at a downward angle.

Can anybody help me find a suitable equation that works no matter where the target is in relation to the cannon?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

墨落成白 2024-09-16 06:52:57

如上所述,没有任何方法可以使顶点低于大炮的高度(而不使重力向后作用)。然而,可以使弹丸穿过火炮下方的点;方程都在这里。您需要求解的方程是:

angle = arctan((v^2 [+-]sqrt(v^4 - g*(x^2+2*y*v^2)))/g*x)

您选择速度并代入目标的 x 和 y 位置 - 假设大炮位于 (0,0)。 [+-] 表示您可以选择任一根。如果平方根函数的参数为​​负(虚数根),则需要更大的速度。因此,如果您处于“范围内”,则对于任何特定速度,您都有两个可能的角度(最大范围 45 度的情况除外,其中两个根应给出相同的答案)。

我怀疑一种轨迹往往会比另一种轨迹“看起来”更明智,但一旦你有了一些东西,那就可以尝试一下。对于目标位于大炮上方的情况,您可能需要坚持使用顶点放牧代码。

As pointed out above, there isn't any way to make the apex be lower than the height of the cannon (without making gravity work backwards). However, it is possible to make the projectile pass through a point below the cannon; the equations are all here. The equation you need to solve is:

angle = arctan((v^2 [+-]sqrt(v^4 - g*(x^2+2*y*v^2)))/g*x)

where you choose a velocity and plug in the x and y positions of the target - assuming the cannon is at (0,0). The [+-] thing means that you can choose either root. If the argument to the square root function is negative (an imaginary root) you need a larger velocity. So, if you are "in range" you have two possible angles for any particular velocity (other than in the maximum range 45 degree case where the two roots should give the same answer).

I suspect one trajectory will tend to 'look' much more sensible than the other, but that's something to play around with once you have something working. You may want to stick with the apex grazing code for the cases where the target is above the cannon.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文