# Fire projectile to hit a moving object

1. Dec 18, 2011

### RuneStrife

This is not a homework problem so i didn't post it in that section, however, it is homework-problem-ish in that it's a problem for a non-school-related programming simluation project I'm working on that I can't solve. If appropriate, please move to that section.

Overview: I'm working on programming a simulation that requires 'shooting' projectile-type objects at other moving objects. How can I calculate the angle at which to shoot the object to hit?

Details:

Imagine you're holding some gun-type object that shoots projectiles at velocity Vd in straight lines. You are moving with Speed Vp at angle Theta_p, in a straight line. Another object, which we will name the target, is located a distance R away from you at an angle Theta_tp, and is moving in a straight ine with velocity Vt at angle Theta_t.

I need to calculate the angle Theta_a I should aim the gun in order to hit the target. The target is moving so you need to lead it with your shot to compensate. Also, the projectile will inherit your velocity on top of its own since you are also moving, which will further modify the angle you need to shoot at.

It seems to me that the strategy should be that I find a point in space which will be occupied by both the projectile and the target. I know all the points in space that the target will take along its linear path, and the times at which it will take all points. However, because the total velocity of the projectile varies based on the angle you shoot it (e.g. the magnitude of the velocity vector will be different depending on what Theta_a you decide to shoot at), I'm not sure how to figure out where to shoot it.

Any help would be appreciated!

In addition, if it is easy, a solution to a target moving in a circular path with radius R (same R as the distance between you and it, so it's making a perfect circle around you) would be appreciated!

Thanks!

2. Dec 18, 2011

### JHamm

Pretend as though your origin is stuck to the gun, add the negative of the guns velocity to the target (same magnitude, just reverse direction), this really will simplify things for you.
Now you can separate the target's velocity into an x-component ($V_{target}\cos \theta_{target}$) and a y-component ($V_{target}\sin \theta_{target}$) and solve these simultaneously with the "bullet's" motion relative to the gun.

3. Dec 18, 2011

### RuneStrife

Thanks for the reply. In fact this has been exactly my approach so far. Before posting this message, I've been able to figure out how to hit a moving target while gun is stationary by doing the following:

1. Figure out the length of the radius between target and gun as a function of time, where gun is always at the origin and not moving.

2. I can then divide that by the magnitude of projectile speed to get a quadratic that gives the time of intersection with the target and get the angle of R at that time.

My problem is that when the gun moves, the magnitude of the projectile speed would vary as a function of the angle you shoot at, because it would inherit the gun's velocity vector (constant angle) plus its own velocity (at the angle to aim) so to calculate the gun's velocity magnitude I'd need to already have the angle I'm looking for.

However, after some thinking I'm going to try to redo the problem through vector addition instead of converting stuff to scalar magnitudes and such, which may (or may not) simplify things.

4. Dec 18, 2011

### Bobbywhy

I think your problem of intercepting a moving object can be solved by using the methods of missile guidance trajectories. Here is an article you may be able to use. See:

http://www.jhuapl.edu/techdigest/TD/...mbo_Homing.pdf

“Figure 2. Planar engagement geometry. The planar intercept problem is illustrated along with most of the angular and Cartesian quantities necessary to derive modern guidance laws.”

5. Dec 18, 2011

### RuneStrife

Actually i was able to solve the problem using the equation:

|T-G-t*(VT-VG)|=D*t

where T and G are target and gun position vectors, VT and VG are velocity vectors for target and gun, D is the projectile default velocity, and || is the magnitude of the sum of those vectors (add the x and y components as above, square them, add that, take the square root, divide by D).

This should give me t to intersect, and then I can plug that in to those X and Y components (from the equation above) and take the atan() of those to get the angle.

Now I moved onto the next step of the problem which is to compare normal inheritance to Directional inheritance, defined such that the projectile only inherits the projection of the gun's velocity on the vector along which it is fired (which is not the vector along which it moves).

Any help with this would also be appreciated. Currently I've modified the vector components in the above equation such that VP components have been changed from:

(VG*cos(Theta_G)i, VG*sin(Theta_G)j)

to:

(VG*cos(Theta_T-Theta_G)^2)i, (VG*cos(Theta_T-Theta_G)sin(Theta_T-Theta_G))j

where Theta_T is the angle defined by the radius drawn from (0,0) to the target and Theta_G is the same thing for the gun.

Does this seem correct, and if not, how to proceed?

Last edited: Dec 18, 2011