## How do I integrate drag over distance?

In my game I want to model kind-of-accurate bullet physics. I have the following drag equation (in C#): float drag = 0.235f * density * velocity*velocity * Mathf.PI * sizeMM*sizeMM/4000000; In non-code terms, this is the same as the drag equation: drag = 0.5 x [density] x [speed]^2 x [area] x [drag coefficient (0.45)] Where density is the density of the material (air being 1.225kg/m^3), velocity is the velocity in m/s, and sizeMM is the diameter of the spherical projectile in mm. 0.235 was obtained by the 1/2 in the drag equation and 0.45 from the drag coefficient for spherical objects, and 4mil was the result of squaring 2000 (2 for halving diameter, 1000 for converting to metres). The drag value appears to be appropriate, for a 11.43mm radius bullet travelling at 251m/s through air, I get a drag value of 1.860946 (presumably in m/s). What I need to be able to do is integrate that over a set distance D to obtain the result velocity as it impacts the target, and I already know that distance value. I'm open to all potential answers to the problem, provided no loops are used. I need the resulting math to be as fast as possible, due to the possibility of it being used upwards of 20 times per second in multi-person combat. I need the resulting math to always use the provided input variables. Density could change based on the material (i.e. flesh, kevlar, wood), sizeMM will change based on the type of ammo, and velocity will obviously change. Approximations are preferred if accurate. If you can give an equation that is within 0.1% of the always-exact one and runs twice as fast, I'd prefer that.

## Solutions/Answers:

### Answer 1:

Only in exceptional circumstances will players notice or care about the accuracy of your physics simulation. Most games fake calculations like these, which has several advantages; fake calculations are easier to code, computationally less expensive and most importantly, they allow the behaviour of the game to be tweaked in favour of fun rather than realism. If playtesting reveals physically accurate bullet drag is less appealing than some other model, faking it becomes a deliberate design choice.

If you still believe realistic drag is an important feature for your game, here’s a bit of physics. The drag equation can be solved analytically, though if you should want to involve other forces on the bullet, you require numerical integration. Combining the drag equation with Newton’s second law of motion, we get: *m v'(t) = -½ v(t)² ρ A C _{d}*, the solution of which is:

*v(t)=2 m / (ρ A C*.

_{d}t + 2 m v(0)^{-1})This gives us the bullet’s speed as a function of time, not of distance, but we can integrate *v(t)* over time to get the distance travelled *x(t)*, then invert that to get the travel time as a function of distance: *t(x) = 2 m(e ^{ρ A Cd x / (2 m)}-1) / ( ρ A C_{d} v(0) )*. The many symbols in this formula obscures its relatively simple exponential nature, which becomes apparent if we simplify

*v(t(x))*, the speed the bullet has when it reaches

*x*:

*v(x) = v(0) e*.

^{-(ρ A Cd/ (2 m)) x}The plot below shows the bullet velocity against distance with the parameters you supplied (air density: 1.225 *kg/m ^{3}*; bullet radius: 11.43

*mm*; initial speed: 251

*m/s*; drag coefficient: 0.45; mass: 10

*g*).

The equation works reasonably well for bullets of different sizes, shapes and masses, but not for different materials. Wood, kevlar and flesh are not fluids and the drag equation does not apply. Newton’s approximation of impact depth may be of some use, but its accuracy is limited, especially for materials like kevlar, which are designed to outperform this approximation.

### Answer 2:

You don’t need to integrate for this.

What you have calculated above is the amount of energy that’s scrubbed off per second.

- Decide what Muzzle Velocity you will have.
- Calculate the Starting Energy of the round in Newtons based on the Mass and Muzzle Velocity.
- Calculate your Time to Target using the Velocity and Distance to Target.
- Multiply Time to Target by your Drag Coefficient to get the Total Energy Lost to the round over its flight.
- Subtract the Total Energy Lost from the Starting Energy to get the Impact Energy at the Target.

The math for this can be done as one line if you build the equation for it.

## References

- Database Administration Tutorials
- Programming Tutorials & IT News
- Linux & DevOps World
- Entertainment & General News
- Games & eSport