# 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.

• "presumably in m/s" I think you'd better take another look at your dimensional analysis... kg/m^3 * (m/s)^2 * m^2 == kg*m^4/(m^3*s^2) == kg*m/s^2 == N. Drag is a force, not a velocity. Also you need to integrate it over time, not distance (more specifically, you need to integrate the acceleration over time to determine the change in velocity, but in the absence of other forces and assuming the bullet has constant mass, they are directly related). Also 0.45 * 0.5 != 0.225 but 0.47 is also a commonly quoted value for spherical drag coeff. Jun 8, 2015 at 3:43
• I did screw up a few things in the question. However, I knew I specifically needed it over distance not time, as I knew that would be computationally less intensive. Jun 9, 2015 at 4:56

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 Cd, the solution of which is: v(t)=2 m / (ρ A Cd 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 Cd 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/m3; 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.

• Far more accurate than my answer haha Way to go! I would also note that instead of trying to calculate impact depth, he may want to simply set a threshold as the penetration velocity. So long as its above that velocity, you treat it as a full puncture. Jun 8, 2015 at 19:43
• Perfect, just what I was looking for. I'll consider impact depth, as that involves relative density, but that poses a problem when it comes to the projectile coming out the other end. Jun 9, 2015 at 4:54

You don't need to integrate for this.

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

1. Decide what Muzzle Velocity you will have.
2. Calculate the Starting Energy of the round in Newtons based on the Mass and Muzzle Velocity.
3. Calculate your Time to Target using the Velocity and Distance to Target.
4. Multiply Time to Target by your Drag Coefficient to get the Total Energy Lost to the round over its flight.
5. 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.