Simulating air resistance
Say you’ve written a nice cloth simulation. Maybe using some cool XPBD physics code following “Ten Minute Physics”. And then you run the demo, which moves around beautifully. There is just one problem: it never stops.
Damping
The problem is that a good simulation has no way to lose energy.
If your simulation code is inaccurate, it’s probably tuned to lose energy. The alternative would be to gain energy which will make the simulation explode. This is based purely on convenience and not on any physics and it usually looks terrible.
A simple hack to emulate losing energy is to multiply all velocities by 99% every second. Unsurprisingly, this also looks terrible, unless you want your cloth to look like it’s underwater.
In reality, where does the energy go? There are many options, so to name a few:
- transferred to other objects
- air
- the strucure the cloth is attached to
- converted to heat and lost to the environment
- due to friction
- due to stretching
Drag and lift
In engineering, the force of air is usually split into two components:
- \( F_D \), the drag force pointing against the airflow
- \( F_L \), the lift force pointing up
A keen observer will note that splitting a three-dimensional force into two scalars that are not even necessarily perpendicular doesn’t make much sense. Luckily engineers only care about airplanes and cars and plugging and chugging. However, they do have an interesting drag equation \[ F_D = \frac{1}{2} \rho v^2 C_D S \] which relates the drag force to the density \( \rho \), the relative velociy \( v \), a drag coefficient \( C_D \) and a reference area \( S \). This formula is also used for lift with \( D \) replaced by \( L \). However, the derivation of this formula seems tp be mostly guesswork combined with dimensional analysis.
Derivation of air resistance
What actually happens to create air resistance? A useful model is that air molecules slam into the object and then they match the speed of the object. Note that air molecules do not bounce (only springs bounce). The mass of air that slams the object in one second is \[ m = \rho |v| A \] where
- \( \rho \), the density of the air
- \( v \), the relative velocity
- \( A \), the area of the object projected in the direction of the relative velocity
Then using Newton’s second law \( F = ma \), we get that: \[ F_D = m \frac{0 -v}{1} = - m v = -\rho v |v| A \]
The difference between the engineering formula above is this version includes direction \( -v / |v| \) and \( \frac{1}{2} C_D S\) is now \( A \). In fact if you look up the \( C_D \) of a flat surface it’s \( 2 \), cancelling out with the \( \frac{1}{2} \). It seems the \( \frac{1}{2} \) was only added in the engineering formula to make it look superficially similar to other formulas.
Where’s my lift, dude?
The above explanation neatly explains drag but it doesn’t explain lift at all. That is because lift is a second order effect, caused by the difference in air pressure around an object. NASA has more in-depth explanations and examples. To properly calculate lift you need to de a computational fluid dynamics simulation of the air. Using the drag equation for lift is a crude approximation.
Of course these second order effects don’t just point up. This means they affect the drag as well. So using the drag equation for drag is a first-order approximation as well.
Simulation
We can use the air resistance formula almost directly. We can use
- \( \rho = 1.2 \, \text{kg} \, \text{m}^{-3} \) as an average air density
- \( v \) calculated as object velocity minus wind velocity
- \( A = S | \hat{v} \cdot n | \), where \( \hat{v} = v / |v| \) and \( S \) is the original area in \( \text{m}^2 \) and \( n \) the normal of the triangle or vertex. Alternatively, without backfaces \( A = S \, \text{max} \left( 0, \hat{v} \cdot n \right) \). Note that you can cancel the factor \( |v| \) with the rest of the expression.
To include second order effects, you can either do the full air simulation or just manually set \( C_D \) and \( C_L \) as Disney did for the movie Frozen (one page “paper”, video).