Hitting a plane with a cannon

Started by
6 comments, last by QTheBrain 22 years, 3 months ago
Hi there, I''m programming a 3D game with DirectX and Visual C++. I''ll get straigth to the problem: in a mission there are several cannons (turrets) placed on the ground. These cannons fire bullets at a constant speed from position p_b with velocity v_b (there''s no gravity now, I''ll add it later with polynomials). THere is also a plane on position p_p and velocity v_p. Note that both velocity and position are vectors in 3D space. The length of v_p and v_b is the distance traveled by the plane/bullet in 1 second. The vector v_p points into the direction the plane is moving, the vector v_b only has a length because i don''t know the angle. My problem is that I don''t know were to aim the cannon in order to hit the plane - the firing angle is unknown. I couldn''t solve it myself, because I didn''t understand how to solve 2 unknowns - the angle and the time. By the time the bullet arrived at p_p the plane was gone. I tried to understand the problem by drawing 2 points and drawing circles around them, where each circle represents a certain time, and i figured out that the cannon always has to shoot bullets faster then the plane. SO assume that |v_b| > |v_p|. If any-one knowns a formula to solve this problem, i would really like to know it. My teacher mathematics couldn''t solve it himself, so i''m really desperate... thanx, Yoshi
Advertisement
It''s a minimization problem - first solve it as far as you can for the two unknowns, then find the minimum time that still hits (subject to the constraints of the angles of the turrets range of motion). Then find the corresponding angle. IRL you''d have to take into account how fast the turret can swivel, to make sure it can reach the postion/angles in time to fire.

The bullet''s dont theorethically have to go faster than the plane - unless the plane is getting farther away from the turret. If it''s coming towards the turret you could lob something slow into the air and still hit the plane if you timed it right.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
the key here is you have to "induce lead" on the target. When your shooting clay pigeons or moving T-80 targets on an m1a1 tank gunnery range you have to shoot in front of the target. The m1a1 has a ballistic computer that calculates the trajectories and angles so the gunner doesn''t have to, he just lays the reticle on the target, lases and blazes. Just think, if you solve this problem, you can get a job with general dynamics land systems!
If you wanted to brute force it...

you could write line equations in the form of p+tv where p i some point t is time and v is the direction of motion.

you could write an exqation for the plane like this.
then you could limit the range of the angle of your cannon like the other poster suggests to something between 0 and 90 degrees.

then you could iterate through the angles the gun can fire at and generate a line equation for each fireing angle.. then set the planes line equation = to the guns fireing line equation and solve for t, you could adjust the magnitude of the v vector to account for different bullet speeds.. etc.

I dont know if this exactly solve the problem your trying to solve, but it''s a start.
Using some of the suggestions of the above posters, I think I've come up with an equation. I did this very fast, so there's probably some mistakes, but I think the theory is sound.

First, to simplify the problem, rotate the whole scene so the planes path is going along the X-axis. (Don' worry, we'll add it back on at the very end).

Now, here comes the tricky part without a diagram. I'll explain with a simple example. Picture the plane going from x=0 to x=n. (x=t). Now at each sample of t, we get a likewise x. Now for this t, we point the cannon directly at the plane (no leading). Plot the point the missile would have gotten to with this t (somewhere on a straight line between the plane and the cannon)Do this for a few t's and you'll see a smooth curve going towards the line of the plane's travel. My missile wasn't going fast enough, so it looked like a asymtope(sp) approaching the line but never getting there. Now, if the missile was going fast enough, the line of the plane and the curved line would cross. This would be your fastest shot (the curve may also curve around and come back, as this problem has 0, 1 or 2 solutions).

The simplest way to do this would be in polar coordinates, but as you may not have done them, and I need a refresher course, we'll stay in cartesians(sp). Heh, all these spelling mistakes...

Now, the equation of the curve is derived as follows (here's where all the math mistakes come in)
We need the angle to the plane at each t first off, and that is
Angle = atan2(Cy-Py, Cx-Px)
where Cy is y of Cannon (Cannon in y anyone?), Py is y of Plane, etc.

Ok, Mx (can you guess what that is?) is
Mx = MSpeed*cos(Angle) (check this... I'm doing this very quickly)
My = MSpeed*sin(Angle)
Now when My = 0 (the plane's line) it's a hit, so...

0 = Cy + MSpeed*sin(atan2(Cy-Py, Cx-Px))
or
0 = Cy + MSpeed*sin(atan2(Cy-0, Cx-PvT)) (Pv = Mag(velocity) of plane, 1 in my example, T = time)

You know everything but T, so solve (if possible... those tricky trig's are everywhere)

Did I make a math or logic mistake anywhere? There's no way I got that all right.

(Oh yeah, add the angle back on that you took off at the very first)

Edit... mistakes already. I'll let you find the rest.

Edited by - Thrump on January 16, 2002 10:06:21 PM
thanx for the equations Thrump!
(also thanx to all others)

i''ll take a fresh look at it tomorrow (i''m a bit sleepy now) together with my math teacher.
if we find any errors in your math, i''ll let you know.

see ya,
Yoshi
Hi Thrump,

what does atan2 mean?
Is it arctan or something?
oh and the thing with reducing the problem to one plane (through missile and plane) is very good - x and y solving is much easier. but i''m wondering, are your equations for a missile that can turn while flying or not? Then it would be for a missile with lock, otherwise it is a rocket that''s flying in a straight line.

Thanx
After I posted, I thought I should have explained it more. For understanding (and solving for T) replace atan2 with arctan. Arctan returns -PI/2 to PI/2 radians (or -90 to 90 degrees). So it only works for half the angles. atan2 is a C math function that returns the full -180 to 180 degrees.
Example:
arctan(1/1) = 45 degrees
arctan(-1/-1) = 45 degrees
You probably wanted -135 degrees, but -1/-1 = 1/1, so arctan is clueless to your intentions. You can write your own version, atan2 will just save you some time. Also, you have to code special cases for artan(1/0) and such. (your computer won''t like 1/0)
Note: the math.h math functions return radians, not degrees.

My curved line does not plot the path of an individual missile. It plots the max a missile can travel for certain times and angles (ie different shots). All singular trips though are straight. I''m not sure if I can explain it any better than the first time.

Picture your cannon just did a perfect shot, and the enemy plane is going down in flames. The cannon is pointed at the point of intercept, right? (ie, if the plane got hit at (10, 10), the cannon would be pointed in that direction, because the missile hit and travelled in a straight line). What my equation does is assume for every moment in time, it was a hit, so the cannon was pointed at the plane''s current position (or at least it was during the shot). So, we point the cannon at the plane at time 1 and see how far the shot went. 1 unit. If the plane is farther than that at time 1, then it was a miss. So we go on to 2, closer this time, but still a miss. Assume time = 3 is a hit. Angle is now 18 degrees. This is the angle you would have had to shoot at. What the equation does is plot all the distances for the infinitely many times (0.1s, 0.1001s, etc.). Can you see that when this curve crosses the flight path of the plane, that it is a hit?

Because:
1)Missile is in planes flight path
2)Missile was origally fired at the angle where plane will be in the future

If anybody else can explain this better (or has a simpler solution), please speak up. If you still don''t understand what the curved line represents, I''ll try and clarify.

This topic is closed to new replies.

Advertisement