I am creating a JavaScript program which simulates fireworks in a 2-dimentional context launching from the ground and exploding somewhere in mid-air.
The program takes into account gravity and drag, but something is wrong with the way I am calculating acceleration due to drag.
Observe these animations:
My implementation of drag physics is producing an undesired, physically inaccurate "square" effect, where particles seem to have a different drag depending on the direction in which they are traveling (the more parallel they are to either the x or y axis, the greater the drag — with the least drag at a 45° angle from either axis). If I turn the drag "off", the firework particles explode evenly in all directions, as they should.
My calculations of acceleration due to drag are based on the following equations:
- D = ½ρCAv² (Nasa)
- a = D/m (Newton's Second Law of Motion)
And these are the snippets of code in the program that I believe are relevant to the problem (However, please feel free to audit the entire source code on GitHub: github.com/foxyjacob/vulcan):
function calculateAccelerationDueToDrag(fluidDensity, dragCoefficient, crossSectionalArea, speed, mass) {
let acceleration = -(0.5 * fluidDensity * dragCoefficient * crossSectionalArea * (speed * speed)) / mass;
if (speed < 0) {
acceleration = -acceleration;
}
return acceleration;
}
...
let accelerationDueToDrag = [
calculateAccelerationDueToDrag(
AIR_DENSITY,
this.dragCoefficient,
this.crossSectionalArea,
lastVelocity[0],
this.mass
),
calculateAccelerationDueToDrag(
AIR_DENSITY,
this.dragCoefficient,
this.crossSectionalArea,
lastVelocity[1],
this.mass
)
];
Essentially, I am calculating each particle's acceleration, velocity, and position on the x and y axes independently.
Why is my model of drag producing this strange "square" effect?

