1
\$\begingroup\$

ballistics

I am trying to determine the gun elevation angle of a gun that fires ballistic projectiles.

For a target at a certain distance D, I will have to compute an angle that increases with D.

This relation ship is non-linear, by the way, because the projectile loses velocity as it travels, for starters, due to drag.

In the past, I have done this with a lookup table.... for a whole bunch of test firings, see where the projectile hits the ground.

But this only works if there is no delta in the elevation between gun and target.

A target that is on a hill top, will need adjustment for extra range. Whereas a target in a valley below, would mean a lower gun elevation.

This means that the table-lookup will break down, and a 2D table seems like a kludge.

What would be an effective way to compute this targeting? I know things also depend on nozzle-velocity and air-drag, but these will not vary (but drag will be non-zero.) Neither will I be modeling the wind.

Additional information:

This is for AI assisted targeting. NPC or player targets a point in the world. The algorithm will find the corresponding angle to hit the target.

Currently, I am using Bullet Physics, with a discretely stepped world.

\$\endgroup\$
3

3 Answers 3

1
\$\begingroup\$

Is this meant for A.I., testing, or educational purposes? This may dictate if approximated methods are an option.

The Wikipedia page on projectile motion is really descriptive on the behavior of 2D ballistics. It includes a section for Angle required to hit coordinate (x,y) and another for when considering air resistance.

Is the speed at which the gun shoots constant? If not, applying a binary search on v while solving for theta might be viable.

\$\endgroup\$
1
  • \$\begingroup\$ This answer would be better if it included the formulas from Wikipedia and showed how to apply them to this problem. As a link, it's possible that an editor later changes / removes that information from the Wikipedia page, leaving this answer less useful than it aims to be. \$\endgroup\$
    – DMGregory
    Dec 22, 2018 at 23:48
0
\$\begingroup\$

Those are good references suggested by @Anko and @Rodrigo Borges I am a Mechanical Engineer, so for fun thought I would answer this question directly and save you sometime:

Given:
v_0: initial velocity of projectile
v_f: final velocity of projectile
g: gravity
a_d: acceleration due to drag (you state constant in your questions, simplifying the physics)
t: time
dt: differential of time
D: distance traveled
x_0: initial position in x
y_0: initial position in y
x_f: final position in x
y_f: final position in y

conservation of momentum:
m*v_f=m*v_0-g*m*t-m*a_d*t
divide by m:
v_f=v_0-g*t-a_d*t
Integrate to get position from velocity:
D=∫(v_0-g*t-a_d*t) dt
D=v_0*t-1/2*g*t^2-1/2*a_d*t^2+const.
distance, D, component wise use basic trigonometry:
y_f=v_0*t*sinθ - 1/2*g*t^2 - 1/2*a_d*t^2*sinθ + y_0
x_f=v_0*t*cosθ - 0 - 1/2*a_d*t^2*cosθ + x_0

Since you know the firing position (x_0,y_0) and the target position (x_f,y_f) You have two unknowns (t & θ) and two equations, so you can solve for both.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks. But v_f is unkown though? And I meant to say aerodynamics dont vary. Drag itself should probably scale w square of vel magnitude? \$\endgroup\$
    – Bram
    Dec 4, 2018 at 14:41
  • \$\begingroup\$ Once you solved for t then substitute and solve for v_f in the equation before integration. Yes, drag is proportional to square of vel. But if you model that in full, all of this gets a lot more complicated. For games, your assumption of constant drag is appropriate and just scale it proportional to the size of objects (larger object receive more drag force). At high velocities, a proportional to square velocity model introduces terminal velocity, the fast speed you can go in air. At low velocity, you won't see a difference on short paths with a constant drag and it will look real. \$\endgroup\$
    – Chris
    Dec 16, 2018 at 18:29
0
\$\begingroup\$

Per @DMGregory who posted a link to Oskar Stålberg's tweet.

By far the easiest solution is a 2D lookup table. Personally, I fill the table by sampling of test firings. I perform test firings by stepping through the range in steps of 0.02 radians, which is 1.146 degrees. For my purposes, this has been accurate enough.

It will be able to handle complex stuff like air drag that scales with the square of the velocity.

The only downside: if you tweak your simulation, you need to re compute the tables.

enter image description here

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .