Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trajectory of a projectile meets a moving object (2D)

Tags:

math

2d

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.

enter image description here

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.

like image 415
sdk Avatar asked Oct 25 '22 14:10

sdk


1 Answers

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.

like image 167
Beta Avatar answered Oct 27 '22 20:10

Beta