Solving the ballistic trajectory equation for Launch Angle

Click For Summary
SUMMARY

The forum discussion focuses on solving the ballistic trajectory equation for determining the launch angle (α) required to hit a target in a game development context. The equation discussed is y = h + x * tan(α) - g * x² / (2 * V₀² * cos²(α)), where all variables except α are known. Participants suggest that while an analytical solution exists for specific cases, such as when the target's height (y_T) equals the launch height (h), a brute force numerical approach is often more practical. The discussion also highlights the potential complexity introduced by factors like air drag, which may necessitate numerical methods for accurate results.

PREREQUISITES
  • Understanding of projectile motion and kinematics
  • Familiarity with the quadratic formula and solving quadratic equations
  • Basic knowledge of trigonometric functions, particularly tangent and arcsine
  • Experience with numerical methods, such as Newton-Raphson for root finding
NEXT STEPS
  • Explore the derivation of the quadratic equation for launch angle using projectile motion equations
  • Learn about numerical methods for solving equations, specifically the Newton-Raphson method
  • Investigate the effects of air drag on projectile motion and how to incorporate it into trajectory calculations
  • Study game physics engines that handle projectile motion for practical implementation insights
USEFUL FOR

Game developers, physics enthusiasts, and anyone involved in simulating projectile motion in software applications will benefit from this discussion.

zazz0000
Messages
10
Reaction score
2
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
 
Physics news on Phys.org
Hello @zazz0000 ,
:welcome: !
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 !

[edit]And the award goes to @PeroK -- see #12 (and #13 :wink: )

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.

Thanks again for the reply!
 
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:
1618325343814.png

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} $$

##\ ##
 
  • #10
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##.
 
  • #11
@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
 
  • #12
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:
  • Like
Likes   Reactions: BvU
  • #13
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 o:) )[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 :biggrin: )

##\ ##
 
Last edited:
  • Like
Likes   Reactions: PeroK
  • #14
BvU said:
One slight improvement $$\tan \alpha = \mu \pm \sqrt{\mu^2 - {\bf 2}\,\mu\tan \theta - 1}$$
Well spotted, thanks.
 
  • #15
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$$
Now it's ready for an application of the Quadratic Formula.
 
  • Like
Likes   Reactions: PeroK
  • #16
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$$
Now it's ready for an application of the Quadratic Formula.
Thanks. It's all the backwards and forwards with this new preview functionality.
 
  • #17
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.
 
  • #18
@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!
 
  • Like
Likes   Reactions: BvU and PeroK
  • #19
Mark44 said:
I agree -- I liked the Preview button where it was.
Me too.
 
  • #20
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.
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
3K
Replies
1
Views
2K
Replies
10
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 25 ·
Replies
25
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K