抛射物的轨迹遇到移动物体 (2D)
我已经寻找了相当长的一段时间,为我的大炮向移动目标发射射弹找到一个很好的数学解决方案,同时考虑到重力。我找到了一种解决方案,可以根据大炮的位置、目标的位置和起始速度来确定大炮的发射角度。该公式如下所述:http://en。 wikipedia.org/wiki/Trajectory_of_a_projectile#Angle_.CE.B8_required_to_hit_cooperative_.28x.2Cy.29。
这非常有效。然而,我的目标是移动的,所以如果我向目标射击,而射弹需要几秒钟才能到达目的地,那么目标早就消失了。可以根据时间确定目标的 x 位置。可以这样说:x = 1000 - (10 * t),其中 t 是以秒为单位的时间。 y 可以描述为:y = t。
问题是,t 取决于大炮发射的角度。
因此我的问题是:如何修改维基中描述的公式,以便将移动目标考虑在内?
此外,我可能在这里或在谷歌上查看了错误的单词,但我没有找到任何描述这个确切问题的解决方案。
预先感谢您的脑力劳动!
作为对您评论的回复。我现在想开火,并且目标在给定速度的射程内。我认为这些都是适用于这个问题的约束。
作为对答案的回复,让我们看一下这个例子:
大炮位于 {0, 0} 并且没有移动。 起始速度为100 m/s。 目标位于{1000, 0},并以 10 m/s 的速度向大炮移动 (v = -10 m/s)。
当我想在 t=0 时(立即)开火时,我应该使用什么角度来击中移动目标?
如果我在不考虑目标速度的情况下射击,我会瞄准{1000, 0},并且可以使用上述公式计算角度。但由于目标在移动,它会严重偏离目标。
正如 Beta 所建议的,我可以瞄准 {500, 0},计算射弹到达这些坐标所需的时间(比方说 5 秒),然后等到目标距离 {500, 0} 5 秒,为{550, 0}。但这意味着我必须等待 450m 或 45 秒才能发射我的大炮。我不想等待,因为目标正在杀死我。
我真的希望这能为您提供足够的信息。我更喜欢一些数学解决方案,但任何能让我真正接近“立即”和“正确命中目标”的东西也非常感激。
I've looked for quite some time now to find a nice math solution for my cannon firing a projectile at a moving target, taking into account the gravity. I've found a solution for determining the angle at which the cannon should be fired, based on the cannon's position, the target's position and the start velocity. The formula is described here: http://en.wikipedia.org/wiki/Trajectory_of_a_projectile#Angle_.CE.B8_required_to_hit_coordinate_.28x.2Cy.29.
This works perfectly. However, my target is moving, so if I shoot at the target and the projectile takes a few seconds to get to its destination, the target is long gone. The target's x position can be determined from the time. Lets say that: x = 1000 - (10 * t) where t is the time in seconds. The y can be described as: y = t.
The problem is, that t depends on the angle at which the cannon is fired.
Therefor my question is: How can I modify the formula as described in the wiki, so that it takes the moving target into account?
Additionally, I might have been looking at the wrong words here or on Google, but I didn't find any solution describing this exact problem.
Thank you in advance for your braintime!
As a reply to your comments. I want to fire it now and the target is in range given the speed. I think that are all constraints that are applicable to this problem.
As a reply to the answer, lets take a look at this example:
The cannon is at {0, 0} and isn't moving.
The start speed is 100 m/s.
The target is at {1000, 0} and is moving with 10 m/s towards the cannon (v = -10 m/s).
What angle should I use to hit the moving target, when I want to fire at t=0 (immediately)?
If I shoot without taking the target's speed into account, I would aim at {1000, 0} and the angle could be calculated using the mentioned formula. But it will miserably miss the target because its moving.
As Beta suggested, I could aim at i.e. {500, 0}, calculate what time it takes for the projectile to arrive at those coords (lets say 5 seconds) and wait until the target is 5 seconds away from {500, 0}, being {550, 0}. But this means that I have to wait 450m or 45 seconds before I can fire my cannon. And I don't want to wait, because the target is killing me in the mean time.
I really hope this gives you enough info to go with. I'd prefer some math solution, but anything that would get me really close to firing "right away" and "right on target" is also much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是约束不足的,这意味着你将有一些选择。你可以在空中追踪目标一段时间,何时开火由你决定。
如果您知道目标的轨迹,并且知道如何击中静止目标,那么您可以选择希望发生撞击的位置。只需在轨迹上选择一个点(舒适地远在目标前面)并瞄准那里。然后你所要做的就是决定何时开火。很容易计算出炮弹需要多长时间才能到达弹着点;很容易计算出目标在到达撞击点之前的时间;当目标到达时,扣动扳机。
The problem is underconstrained, which means that you will have some choices. You can track the target through the air for a while, and the choice of when to fire is up to you.
If you know the target's trajectory, and you know how to hit a stationary target, then you can choose where you want the impact to occur. Just pick a point on the trajectory (comfortably far ahead of the target) and aim there. Then all you have to do is decide when to fire. It is easy to calculate how long the cannonball will take to reach the point of impact; it is easy to calculate where the target will be, that much time before it reaches the point of impact; when the target is there, pull the trigger.
我怀疑找到一个公式会非常困难。然而,下面的迭代方案中的误差每一步都会大约下降 v/V(v 目标速度,V 弹丸速度)。
首先将飞行时间设为零
重复
计算到目标的距离(使用飞行时间)
根据距离计算飞行时间。
直到连续两次飞行足够接近
I suspect finding a formula will be quite difficult. However the error in the iterative scheme below will go down by roughly a factor of v/V (v the target speed, V the projectile speed) each step.
start by taking the time of flight to be zero
Repeat
calculate the distance to the target (using time of flight)
calculate the time of flight from the distance.
Until two successive times of flight are close enough