Need some help with ballistic math
by David Erenger · in Technical Issues · 10/21/2005 (6:07 am) · 55 replies
Hi!
I'm working on an rts and have a problem with the math..
I have bullet ballistics without drag and I need to calculate the angle to fire for the projectile to hit a point..
If I understand the math right there is two angles that will result in a hit like this.

I need both angles, the long for my artillery and the second for directhit units like tanks and rifles.
I have made an aproximation that works pretty well for direct hit bullets at short ranges but it doasnt do the trick for me anymore :/...
So I thougt I could calculate the real ekvation for a.
I can use this ekvation:
y = x tan(a) - g / (2Vo^2 cos(a)^2) * x^2
The x, y, Vo and g are all given, the only thing I need is a.
I have tried a couple of hours to get out the a but without 100% succes :(
So if there is anyone with some greater math skills then me please help me with this...
Thanks all
I'm working on an rts and have a problem with the math..
I have bullet ballistics without drag and I need to calculate the angle to fire for the projectile to hit a point..
If I understand the math right there is two angles that will result in a hit like this.

I need both angles, the long for my artillery and the second for directhit units like tanks and rifles.
I have made an aproximation that works pretty well for direct hit bullets at short ranges but it doasnt do the trick for me anymore :/...
So I thougt I could calculate the real ekvation for a.
I can use this ekvation:
y = x tan(a) - g / (2Vo^2 cos(a)^2) * x^2
The x, y, Vo and g are all given, the only thing I need is a.
I have tried a couple of hours to get out the a but without 100% succes :(
So if there is anyone with some greater math skills then me please help me with this...
Thanks all
#2
x and y is the point where the projectile will hit in proposion with the starting point s
10/21/2005 (7:46 am)
Yeah I can put different values in but I need it in program,x and y is the point where the projectile will hit in proposion with the starting point s
#3
a = ( sin^-1 * ( (g*x) / Vo^2 ) ) / 2
Derived from:
x = ( Vo^2 * sin (2*a) ) / g
The two angles are a and 90-a.
10/21/2005 (8:02 am)
Is this the equation you're looking for? :a = ( sin^-1 * ( (g*x) / Vo^2 ) ) / 2
Derived from:
x = ( Vo^2 * sin (2*a) ) / g
The two angles are a and 90-a.
#4
I'll try it, thank you very mutch
10/21/2005 (8:10 am)
That looks realy promising I'll try it out... but one thing, y? this ekvation asumes that the target is at the same hight as the attacker...I'll try it, thank you very mutch
#5
hyperphysics.phy-astr.gsu.edu/hbase/traj.html
Click On "Range and Time for Given Height" bubble in the map.
10/21/2005 (8:30 am)
David: For the full treatment with varying elevations go to:hyperphysics.phy-astr.gsu.edu/hbase/traj.html
Click On "Range and Time for Given Height" bubble in the map.
#6
10/21/2005 (8:32 am)
Yes, it assumes equal height for source and destination. I assumed from your drawings you wanted this. I'll give it another go after some coffee.
#7
This is the direct link to hyperphysics html application list. Very useful when a gamer is trying to figure out and verify concepts. Contains mini-applets for everything.
hyperphysics.phy-astr.gsu.edu/hbase/hframe.html
10/21/2005 (8:42 am)
Just another note:This is the direct link to hyperphysics html application list. Very useful when a gamer is trying to figure out and verify concepts. Contains mini-applets for everything.
hyperphysics.phy-astr.gsu.edu/hbase/hframe.html
#8
@Jerry, my bad didnt thought of that when I draw that image :/
@Tim, I looked at the site you pointed to and I thinks its real cool but I know the concepts and ekvations they are providing allready, I might have missed something but there is not any examples how to calculate the angle to hit a given point. for the "Range and Time for Given Height" you feed it with the y, Vox, Voy and the angle and get out x, I dont think I can use that.
Maby Its obvious but I cant find it :(..
So Jerry If you find some time please can you solve the ekvation so I can put in the hight to?
Or maby you, Tim knows the way to go?
10/23/2005 (12:57 pm)
Thanks for your responses.@Jerry, my bad didnt thought of that when I draw that image :/
@Tim, I looked at the site you pointed to and I thinks its real cool but I know the concepts and ekvations they are providing allready, I might have missed something but there is not any examples how to calculate the angle to hit a given point. for the "Range and Time for Given Height" you feed it with the y, Vox, Voy and the angle and get out x, I dont think I can use that.
Maby Its obvious but I cant find it :(..
So Jerry If you find some time please can you solve the ekvation so I can put in the hight to?
Or maby you, Tim knows the way to go?
#9
But here's a possible answer for you, taken from the "Physics for Game Developers", pg 104-105:
v0 is the magnitude of the initial velocity
vx(t) is the x speed at time t
vy(t) is the y speed at time t
a is the launch angle
h is the maximum height of the projectile
b is the landing height of the projectile
R is the total distance traveled in x
Formulas for Targets higher than the Launch Point
x(t) = v0*cos(a)*t
y(t) = v0*sin(a)*t
vx(t) = v0*c0s(a)
vy(t) = v0*sin(a)-g*t
v(t) = sqrt(v0^2 - 2*g*t*v0*sin(a) + (g*t)^2)
h = (v0^2 * sin(a)^2)/(2*g)
R = v0*T*cos(a)
T = (v0*sin(a)/g + sqrt(2*(h-b)/g)
Formulas for Targets lower than the Launch Point
x(t) = v0*cos(a)*t
y(t) = v0*sin(a)*t
vx(t) = v0*cos(a)
vy(t) = v0*sin(a)-g*t
v(t) = sqrt(v0^2 - 2*g*t*v0*sin(a) + (g*t)^2)
h = b + (v0^2 * sin(a)^2)/(2*g)
R = v0*T*cos(a)
T = (v0*sin(a)/g + sqrt(2*h/g)
Decide whether the target is above of below your canon. Assuming you
have selectd the position down range, R, and selected V0, the projectile speed and h, the maximum height,
and b the impact height, these reduce to the following (at least when I did it).
Use this for the first case, target above the gun:
a = acos( R*sqrt(g) / (v0 * (sqrt(2*h)+sqrt(2*h-b)))
and this for the case of target below the gun:
a = acos( R*sqrt(g) / (2*V0*sqrt(2h))
You can use the hyperphysics resource to verify some of this with specific values plugged in to the apps.
10/23/2005 (2:20 pm)
David: I know the site doesn't give you precisely the solution your looking for, but it's a great resource for you to use as you develop the solution.But here's a possible answer for you, taken from the "Physics for Game Developers", pg 104-105:
v0 is the magnitude of the initial velocity
vx(t) is the x speed at time t
vy(t) is the y speed at time t
a is the launch angle
h is the maximum height of the projectile
b is the landing height of the projectile
R is the total distance traveled in x
Formulas for Targets higher than the Launch Point
x(t) = v0*cos(a)*t
y(t) = v0*sin(a)*t
vx(t) = v0*c0s(a)
vy(t) = v0*sin(a)-g*t
v(t) = sqrt(v0^2 - 2*g*t*v0*sin(a) + (g*t)^2)
h = (v0^2 * sin(a)^2)/(2*g)
R = v0*T*cos(a)
T = (v0*sin(a)/g + sqrt(2*(h-b)/g)
Formulas for Targets lower than the Launch Point
x(t) = v0*cos(a)*t
y(t) = v0*sin(a)*t
vx(t) = v0*cos(a)
vy(t) = v0*sin(a)-g*t
v(t) = sqrt(v0^2 - 2*g*t*v0*sin(a) + (g*t)^2)
h = b + (v0^2 * sin(a)^2)/(2*g)
R = v0*T*cos(a)
T = (v0*sin(a)/g + sqrt(2*h/g)
Decide whether the target is above of below your canon. Assuming you
have selectd the position down range, R, and selected V0, the projectile speed and h, the maximum height,
and b the impact height, these reduce to the following (at least when I did it).
Use this for the first case, target above the gun:
a = acos( R*sqrt(g) / (v0 * (sqrt(2*h)+sqrt(2*h-b)))
and this for the case of target below the gun:
a = acos( R*sqrt(g) / (2*V0*sqrt(2h))
You can use the hyperphysics resource to verify some of this with specific values plugged in to the apps.
#10
I have to sleep now, I'll try it tomorow.
But one thing, maby I'm just tired but is it realy possible to get h before I have the angle a?
well, I'l take a look at it tomorow, thanks for not giving up on me :)
10/23/2005 (3:30 pm)
Great thanks,I have to sleep now, I'll try it tomorow.
But one thing, maby I'm just tired but is it realy possible to get h before I have the angle a?
well, I'l take a look at it tomorow, thanks for not giving up on me :)
#11
So for that, y = Vy*t - 1/2*gt^2. Let y be the landing elevation,h, and t = T, the time needed to reach R.
so Vy = h/T + 1/2*g*T and a = atan( (h*Vx/R +1/2*g*R/Vx)/Vx)
or
a = atan(h/R + g*R/(2*Vx^2)
the muzzle velocity would then need to be
V = sqrt(Vy^2 + Vx^2)
Hope that makes sense because it's just off the top of my head as an easy way out of figuring out the general
form of the projectile equations, where the launch angle is unknown. I did not find any clever web links for that.
Maybe someone else has the time and inclination for that.
10/24/2005 (5:37 pm)
One way to simplify the problem, (because it is underdetermined), is to assume that, for the purpose of the game, the muzzle velocity is not known but the x velocity is some useful value, Vx, like 300 m/sec. This allows you to calculate the arrival time, T, downrange as simply T = R/Vx. Then finding the launch angle a is the same as finding the vertical component of the launch velocity, Vy, where a = atan(Vy/Vx), such that the projectile arrives at the height, h, at the required time, T. So for that, y = Vy*t - 1/2*gt^2. Let y be the landing elevation,h, and t = T, the time needed to reach R.
so Vy = h/T + 1/2*g*T and a = atan( (h*Vx/R +1/2*g*R/Vx)/Vx)
or
a = atan(h/R + g*R/(2*Vx^2)
the muzzle velocity would then need to be
V = sqrt(Vy^2 + Vx^2)
Hope that makes sense because it's just off the top of my head as an easy way out of figuring out the general
form of the projectile equations, where the launch angle is unknown. I did not find any clever web links for that.
Maybe someone else has the time and inclination for that.
#12
Vy = (h +((g*(R / Vx)*(R / Vx))/2))/(R / Vx);
a = mAtan(Vx,Vy);
but it is driving me crazy that there is no "real" solution for this, I get back to you when (if) I find out a better way to do it. I have emailed the question to a math professor, maby he knows a way :)
Thanks for your help everyone
10/26/2005 (12:11 am)
@Tim, I'll will use a solution like yours for now.Vy = (h +((g*(R / Vx)*(R / Vx))/2))/(R / Vx);
a = mAtan(Vx,Vy);
but it is driving me crazy that there is no "real" solution for this, I get back to you when (if) I find out a better way to do it. I have emailed the question to a math professor, maby he knows a way :)
Thanks for your help everyone
#13
10/26/2005 (6:32 am)
Using the fact that h is reached when the slope is zero should be enough information to eliminate it from the equations using the derivative but I can't get my brain around it. :) Good luck.
#14
for your projectiles you need to choose a maximum vertical distance, horizontal distance, and a time. those are the only variables which you should choose. everything else comes out of the calculations. you should let your choice of distance and time determine the initial velocity and angle.
10/26/2005 (7:25 am)
David you need to take a different approach. you are trying to use standard ballistic equations in an unconventional way. you can achieve the situation you want but you have to allow more of the variables to be calculated. for your projectiles you need to choose a maximum vertical distance, horizontal distance, and a time. those are the only variables which you should choose. everything else comes out of the calculations. you should let your choice of distance and time determine the initial velocity and angle.
#15
10/26/2005 (7:38 am)
Sean, it's more complicated than that. Suppose you are an artillery commander with a certain cannon and shell. Your muzzle velocity is fixed. You won't know the height until you calculate the angle. So just how does a field artillery person calculate his angle? I think the question is kind of interesting, actually. But I couldn't Google up any relevant links for the problem posed that way, just the standard exposition of the problem.
#16
if you're creating a situation where a projectile travels a realistic trajectory, then the starting velocity and angle must be given. the vertical and horizontal distance is based on these parameters. if you're creating a situation where a position is targeted, then the angle and velocity should be calculated based on the distances and travel time.
10/26/2005 (8:29 am)
In that case your vertical and horizontal distance would depend on the angle and velocity. theres no angle calculation to be made. the projectile will travel a given vertical and horizontal distance based on the angle of the gun and the muzzle velocity. if you're creating a situation where a projectile travels a realistic trajectory, then the starting velocity and angle must be given. the vertical and horizontal distance is based on these parameters. if you're creating a situation where a position is targeted, then the angle and velocity should be calculated based on the distances and travel time.
#17
That is what we are trying to do here, except the velocity is given. But the hard part is how to calculate the angle, not what has to be done
10/26/2005 (8:37 am)
Quote:if you're creating a situation where a position is targeted,then the angle and velocity should be calculated based on the distances and travel time.
That is what we are trying to do here, except the velocity is given. But the hard part is how to calculate the angle, not what has to be done
#18
But vertical and horizontal distance are not dependent, they are part of the given data, along with muzzle velocity. Think of a firing a mortar, you don't care how high it goes or how long it takes - just where it lands. If the height needs to be calculated in an intermediate step, it can't depend on the angle unless a system of equations with the two unknowns can be constructed and solved. That's the issue, I think. Maybe there is a trig substitution I missed somewhere above that would eliminate it.
10/26/2005 (8:39 am)
"In that case your vertical and horizontal distance would depend on the angle and velocity"But vertical and horizontal distance are not dependent, they are part of the given data, along with muzzle velocity. Think of a firing a mortar, you don't care how high it goes or how long it takes - just where it lands. If the height needs to be calculated in an intermediate step, it can't depend on the angle unless a system of equations with the two unknowns can be constructed and solved. That's the issue, I think. Maybe there is a trig substitution I missed somewhere above that would eliminate it.
#19
10/26/2005 (8:48 am)
Maybe an iterative solver that minimizes time of flight or height is the way it's done.
#20
Ahh...i c now. yeah that is interesting. I'll see what i can come up with.
10/26/2005 (8:50 am)
"That is what we are trying to do here, except the velocity is given. But the hard part is how to calculate the angle, not what has to be done"Ahh...i c now. yeah that is interesting. I'll see what i can come up with.
Torque 3D Owner Sean H.