Easy Question: Formula for Launch Angle? Projectile Motion.

In summary, the AI mortar can determine the coordinates to aim at to hit a target moving in a straight line with constant velocity by solving for the angle and bearing needed and taking into account the time to impact.
  • #1
jllorens
8
0
Edit: I solved my problem for launch angle. So now I have another question.

I am writing a script for a cannon in a video game that will aim at XYZ coordinates by determining the angle and bearing needed to launch the projectile to hit the target. I wish to add a target-leading formula so that it can lead targets moving in a straight line with constant velocity.

The problem is that the time to impact, "t," must be factored into determining the coordinates to aim at in order to lead the target, but in order to determine the time to impact, the coordinates must be known.

So, given the current XYZ of the target, the initial XYZ of the projectile, the initial velocity of the projectile, and the velocity of the target, is there any way to solve for the XYZ of where the target will be in an unknown timespan "t" (the flight time of the projectile)?
 
Last edited:
Physics news on Phys.org
  • #2
You need to be solving a pair of simultaneous equations. Alternatively, you could google trajectories/ballistics/artillery and there is bound to be a formula in there somewhere. (I chucked out my School Maths note book nearly fifty years ago but is was in there somewhere.)
 
  • #3
The equation of trajectory might be helpful in finding out the desired result.Although,it may lead to complex mathematics.
 
  • #4
It depends on what you call complex. If you are making a video game then you are, presumably, using a processor and a programming language. All the languages can evaluate simple mathematical expressions. The shape of the trajectory need not be too accurate as long as the ends are in the right place.
 
  • #5
It seems to me that there are too many unknowns.

I have the trajectory equation down, I can get the right angle to hit any target at any elevation (assuming it is within range) with a mortar shot (high angle shot as opposed to low angle).

But the target leading seems to require a "guess and check" method. The problem with such a method is that it takes time for a computer to run, time that during which, the target will move thus altering the "future position" at a time T seconds from the moment of calculation, so this method basically forces itself to give a wrong answer simply because of the time it takes to perform.

I don't know if it is possible, unless you could somehow get an equation for T (time of flight) that does not require X and Y to be known (2d projectile motion).

Plus it just logically feels like an impossible thing to answer. It is like asking someone with a giant supercomputer that could compute the probabilities at a subatomic level to predict the future:

"What happens at a precise moment in time in the future?"

"Well when is this precise moment in time?"

"I don't know."
 
Last edited:
  • #6
I see your problem. It looks like you would need some successive approximation loop. Not too hard, though, because they used to use 'predictors' on AKAK guns in the WW2 and they would have been really sluggish, analogue things. The time taken would depend upon the required accuracy.

BTW, you say you can do the 'mortar' trajectory and not the 'field gun' trajectory. They both just involve the two possible roots of the quadratic equation so either should be just as easy. (no?)
 
  • #7
  • #8
I was just working out the details of this same exact problem for an AI mortar for a game. Here is what I've come up with. I am not using standard spherical coordinates so I have tried to designate my angles using different designations than usual.

α is the change in angle from the position of the target and where the target will be when the projectile hits the ground.

t = 2v/g cos(ψ)

where ψ is the angle from the z-axis (I assume z is pointing upwards), and v is the muzzle velocity. The AI engine is going to be aware of the NPC's position at any given time. so at t=t₀ the NPC is located at (x₀, y₀, z₀). At t = 2v/g cos(ψ) the NPC is located at (x₁, y₁, z₁).

Since the target is moving with velocity u along some (hopefully predictable) path. we can describe the path using some function. For my purposes these are lines but you may do something different so let's just say.

r(t) is some vector function that returns a position at a given time. We can then use the distance formula to calculate the distances between the current position and the landing position.

d₁ = distance between current position of target
d₂ = distance between me and target after the projectile flies

These give me a triangle where the only missing side is the side connecting these two points to each other. For me this is easy to handle using r(t) = vt but in general, you can use the average value formula to connect these. Thus your AI won't be dead perfect at shooting NPC's but it will be darn close. We will call that other side d₂₁ and across from it was our earlier presented angle α.

cos(α) = ((d₁)² + (d₂)² - (d₂₁)²)/(2√(d₁d₂))

Which as you imagine came from the law of cosines, but more importantly, this one is not too computationally expensive depending on what your r(t) function looks like. In my code these distances had to be calculated for something else anyway so the algorithm made sense and it is not some recursive type function that reduces error with each iteration like you'd been suggested to use previously.
 
  • #9
jllorens said:
Edit: I solved my problem for launch angle. So now I have another question.

I am writing a script for a cannon in a video game that will aim at XYZ coordinates by determining the angle and bearing needed to launch the projectile to hit the target. I wish to add a target-leading formula so that it can lead targets moving in a straight line with constant velocity.

The problem is that the time to impact, "t," must be factored into determining the coordinates to aim at in order to lead the target, but in order to determine the time to impact, the coordinates must be known.

So, given the current XYZ of the target, the initial XYZ of the projectile, the initial velocity of the projectile, and the velocity of the target, is there any way to solve for the XYZ of where the target will be in an unknown timespan "t" (the flight time of the projectile)?

On a quick note, just be aware that "the time factored in" is only dependent on your angle of launch from the vertical, not the bearing. That is where my t = 2v/g cos(ψ) came from.

That time is basically constant in particular you can choose for your AI to launch at ψ = π/4 for all your calculations to simplify things substantially.
 

1. What is the formula for calculating launch angle in projectile motion?

The formula for launch angle in projectile motion is given by θ = tan-1(vy/vx), where θ is the launch angle, vy is the vertical velocity, and vx is the horizontal velocity.

2. How do I determine the launch angle if I know the initial velocity and range of a projectile?

To determine the launch angle, you can use the formula θ = sin-1(range*g/velocity2), where θ is the launch angle, range is the horizontal distance traveled by the projectile, g is the acceleration due to gravity, and velocity is the initial velocity of the projectile.

3. Can the launch angle of a projectile affect its range?

Yes, the launch angle can greatly affect the range of a projectile. The optimum launch angle for maximum range is 45 degrees, but this may vary depending on the initial velocity and other factors such as air resistance.

4. Is there a specific launch angle for a projectile to achieve maximum height?

Yes, the optimum launch angle for maximum height is 90 degrees. This means that the projectile is launched straight up with a vertical velocity, resulting in a parabolic trajectory and maximum height.

5. How does the launch angle affect the trajectory of a projectile?

The launch angle greatly affects the trajectory of a projectile. A lower launch angle will result in a flatter trajectory, while a higher launch angle will result in a steeper trajectory. The launch angle also determines the shape and height of the projectile's curved path.

Similar threads

Replies
4
Views
1K
Replies
4
Views
839
Replies
16
Views
1K
Replies
8
Views
2K
Replies
8
Views
2K
  • Introductory Physics Homework Help
Replies
7
Views
2K
Replies
6
Views
3K
Replies
2
Views
1K
  • Mechanics
Replies
2
Views
1K
Replies
17
Views
17K
Back
Top