# Solving the ballistic trajectory equation for Launch Angle

• Comp Sci
• zazz0000
In summary: That's right, the starting height and the range. The range is the maximum distance from the helicopter or vehicle to the target.

#### zazz0000

Homework Statement
Solving the ballistic trajectory equation for Launch Angle
Relevant Equations
y = h + x * tan(α) - g * x² / 2 * V₀² * cos²(α)
In a process of writing a game. Effectively need to know how to angle the barrel for the projectile to hit the selected target.
So for the equation

y = h + x * tan(α) - g * x² / 2 * V₀² * cos²(α)

Everything except α is known. Could anyone more wise in the ways of science than me help me solve for alpha?

Thanks

Hello @zazz0000 ,
!
Your y = h + x * tan(α) - 1/2 g * ( x / ( V₀ cos α) )² (note the use of brackets !) requires some explanation ! It is the equation for a parabola that starts at ##\ (x,y) = (0, h)\ ## with a slope ##\tan \alpha## and a speed ##v_0##.

Another (equivalent) representation is in terms of time ##t##: \begin{align*} x&=\ \phantom{h +}v_0\cos\alpha\ t \\ y&=h + v_0\sin \alpha\ t - {1\over 2} g\,t^2 \end{align*}You will recognize the equivalence if you substitute ##\ t = x/(v_0\cos\alpha)\ ##, right ?

To hit a 'selected target', it is useful to know its coordinates ##(x_T, y_T)\ ##

Solving this amounts to solving two equations (##\;x_T = .. \ \& \ y_T = .. \ ##, see above) with two unknowns (##t## and ##\alpha## ).

The case ## y_T = h ## is 'solved' here to give $$\alpha = {1\over 2}\arcsin \left ( g\, x_T\over v_0^2 \right )$$(with zero or two solutions!)

The general case seems to be carefully avoided in the many examples I find googling 'projectile trajectory' (but you want to look at a few of them anyway to get a feeling for game physics !).
And from just looking at it, I don't see any clever analytical solution, but I would be happy to be proven wrong !

And the award goes to @PeroK -- see #12 (and #13 )

Even if there is an analytical solution: the next refinement is to add air drag and then you are back to having to do it numerically anyway...

##\ ##

Last edited:
Hi @BvU

Appreciate the response and the breakdown.
I've been scouring the internet and other various resources and as you point out, the case does seem to be generally avoided.
So it seems like there's no elegant solution for solving for α here (unless I'm looking right past it).

Full disclosure, for the purposes of my project I, having exhausted most other options, decided to take a brute force approach and simply testing the original function for arbitrary values of α, adjusting them based on some heuristic and retesting until the result puts me within a set tolerance for accuracy. The results are very good so far and if I can come up with a better heuristic it seems that I would be able to find an acceptable α in under 10 iterations or so.

As for having air drag, while tempting, I would have to justify implementing it for projectiles. I currently use air drag for vehicles in a simplified form of R = ½v^2 * drag, where drag is a constant representing the combination of fluid density, drag coefficient and reference area (for my purposes, all those can remain constant). If I can incorporate that into the original trajectory function, it might just be worth it.

zazz0000 said:
Full disclosure, for the purposes of my project I, having exhausted most other options, decided to take a brute force approach and simply testing the original function for arbitrary values of α, adjusting them based on some heuristic and retesting until the result puts me within a set tolerance for accuracy. The results are very good so far and if I can come up with a better heuristic it seems that I would be able to find an acceptable α in under 10 iterations or so.
Numerical solution is one way (Newton-Raphson is very fast with fair initial guesses), and if it's a game you might consider cheating: the analytical solution for ##\ y_T=h\ ## plus a straight line sloping from ##h## to ##y_T## can hardly be distinguished from the correct solution
Wikipedia said:

I don't know your context (bullet, arrow, cannonball shooting, throwing ?) so it's hard to say anything further ...

##\ ##

For context, I am shooting bullets or unguided rockets from a helicopter or a ground vehicle.
The ranges can be pretty long, I'd say over a kilometer, while the travel speed of the projectile is currently significantly lower than the real-life counterparts, for example 120m/s vs an actual cannon that would be somewhere around Mach 3.

zazz0000 said:
For context, I am shooting bullets or unguided rockets from a helicopter or a ground vehicle.
The ranges can be pretty long, I'd say over a kilometer, while the travel speed of the projectile is currently significantly lower than the real-life counterparts, for example 120m/s vs an actual cannon that would be somewhere around Mach 3.
You know the starting height ##h## and the velocity ##v_0## and you want to find the launch angle required to hit a fixed target ##(X, Y)##?

@PeroK that is correct, yes. I suppose it's safe to say that Y will always be zero (not sure if that's of any help)

zazz0000 said:
@PeroK that is correct, yes. I suppose it's safe to say that Y will always be zero (not sure if that's of any help)
You should be able to get a quadratic equation for the tangent of the launch angle. It may be a bit messy, but you just put these two equations together, by getting rid of ##t##:
BvU said:
\begin{align*} x&=\ \phantom{h +}v_0\cos\alpha\ t \\ y&=h + v_0\sin \alpha\ t - {1\over 2} g\,t^2 \end{align*}

Getting rid of ##t## results in OP's original equation. For ##\alpha## that's like $$y_T - h = x_T\tan\alpha - {1\over 2} g\left ( x_T\over v_0\right)^2{1\over\cos^2\alpha}$$

##\ ##

BvU said:
Getting rid of ##t## results in OP's original equation. For ##\alpha## that's like $$y_T - h = x_T\tan\alpha - {1\over 2} g\left ( x_T\over v_0\right)^2{1\over\cos^2\alpha}$$

##\ ##
That's a quadratic in ##\tan \alpha## if you use ##\sec^2 \alpha = 1 + \tan^2 \alpha##.

@PeroK I'm not quite as nimble as you are I'm sure as far as math goes, what would the quadratic look like in the end? And ultimately, how would that be solved for α?

P.S. I really appreciate you guys helping me on this, I thought this thread was going to go unnoticed and ultimately die

zazz0000 said:
@PeroK I'm not quite as nimble as you are I'm sure as far as math goes, what would the quadratic look like in the end? And ultimately, how would that be solved for α?

P.S. I really appreciate you guys helping me on this, I thought this thread was going to go unnoticed and ultimately die
You can simplify things a bit, by setting ##\mu = \frac{v_0^2}{gx_T}##, which is dimensionless. And, noting that ##\frac{y_T - h}{x_T} = \tan \theta## is the tangent of the angle from the launch point to the target. This gives: $$\tan \theta = \tan \alpha - \frac{1}{2\mu}(1 + \tan^2 \alpha)$$ Re-arranging gives:
$$\tan^2 \alpha - 2\mu \tan \alpha + 1 + 2\mu \tan \theta = 0$$ And if you hit that with the quadratic formula you get: $$\tan \alpha = \mu \pm \sqrt{\mu^2 - 2\mu\tan \theta - 1}$$
We can check that in the case when ##\theta = 0## we agree with the result above:
BvU said:
$$\alpha = {1\over 2}\arcsin \left ( g\, x_T\over v_0^2 \right )$$
That solution is $$\sin 2\alpha = \frac 1 {\mu}$$ Whereas, we have: $$\tan \alpha = \mu \pm \sqrt{\mu^2 - 1}$$ We can use the trig identity:
$$\sin 2\alpha = \frac{2\tan \alpha}{1 + \tan^2 \alpha} = \frac{2(\mu \pm \sqrt{\mu^2 - 1})}{2(\mu^2 \pm \mu\sqrt{\mu^2 - 1})} = \frac 1 \mu$$ And that checks out.

Last edited:
BvU
I'm impressed ! So much fun with a simple parabola !
One slight improvement $$\tan \alpha = \mu \pm \sqrt{\mu^2 - {\bf 2}\,\mu\tan \theta - 1}$$

(popped up when I was checking with a simple Excel ( ) example -- that I had to retype from scratch since I forgot to save it yesterday )[added]:

And that way it dawns on me that
BvU said:
the analytical solution for yT=h plus a straight line sloping from h to yT can hardly be distinguished from the correct solution
Is not miraculous: it is the analytical solution -- you just shouldn't make a mess of things in Excel (as is virtually unavoidable )

##\ ##

Last edited:
PeroK
BvU said:
One slight improvement $$\tan \alpha = \mu \pm \sqrt{\mu^2 - {\bf 2}\,\mu\tan \theta - 1}$$
Well spotted, thanks.

Another slight improvement:
PeroK said:
Re-arranging gives:$$\tan^2 \alpha - 2\mu \tan \alpha + 1 + 2\mu \tan \theta$$
Make this an equation and I'll be happy
$$\tan^2 \alpha - 2\mu \tan \alpha + 1 + 2\mu \tan \theta = 0$$

PeroK
Mark44 said:
Another slight improvement:

Make this an equation and I'll be happy
$$\tan^2 \alpha - 2\mu \tan \alpha + 1 + 2\mu \tan \theta = 0$$
Thanks. It's all the backwards and forwards with this new preview functionality.

PeroK said:
Thanks. It's all the backwards and forwards with this new preview functionality.
I agree -- I liked the Preview button where it was.

@BvU @PeroK @Mark44
Wow thanks guys, this is awesome! Works flawlessly.
Plus this resource is really nice to have out there, since hours and hours of googling didn't yield a solution for this, even though it seems like a very useful function.

Thanks again!

BvU and PeroK
Mark44 said:
I agree -- I liked the Preview button where it was.
Me too.

Late addition just for the record:
$$sin(\theta+\gamma)=\frac{gx}{uv}.$$Then $$\tan\theta=\frac{u-v\cos(\theta+\gamma)}{v\sin(\theta+\gamma)}.$$ There will be 2 answers for the first equation and hence two values of ##\theta##.##v=\sqrt{(u^2-2gh)}\;##,##\;\theta## is the projection angle and ##\gamma## is the impact angle both measured from the horizontal.

## 1. What is the ballistic trajectory equation for launch angle?

The ballistic trajectory equation for launch angle is a mathematical formula that describes the path of a projectile in motion, taking into account the initial velocity, launch angle, and gravitational force.

## 2. How is the launch angle calculated in the ballistic trajectory equation?

The launch angle is calculated using trigonometric functions, specifically the tangent function. The formula is: launch angle = arctan(vertical velocity / horizontal velocity).

## 3. What factors can affect the launch angle in the ballistic trajectory equation?

The launch angle can be affected by various factors such as the initial velocity, air resistance, and the gravitational force. It can also be influenced by external factors such as wind and elevation changes.

## 4. Can the ballistic trajectory equation be used for any type of projectile?

Yes, the ballistic trajectory equation can be used for any type of projectile as long as the initial velocity, launch angle, and gravitational force are known. This includes objects such as bullets, rockets, and even sports balls.

## 5. How is the ballistic trajectory equation for launch angle applied in real-life situations?

The ballistic trajectory equation is commonly used in fields such as physics, engineering, and ballistics. It is used to predict the trajectory of projectiles in various scenarios, such as in sports, military operations, and space exploration.