-1

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:

  1. Without drag

    enter image description here

  2. With drag

    enter image description here

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:

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?

Qmechanic
  • 220,844

1 Answers1

3

With a drag force proportional to velocity$^2$, you can't do the calculations for the $x$ and $y$ directions separately. $$\vec{D} = -k|\vec{v}|^2\hat{v} = -k|\vec{v}|\vec{v}$$ Therefore, $$D_{x} = -k\sqrt{v_x^2 + v_y^2}\ v_x$$ You can't just send the $x$-component of the velocity of the projectile to to the function to get the $x$-component of the drag force. Your calculateAccelerationDueToDrag() function needs to have inputs for both velocity components for both drag components.

Related:

Mark H
  • 25,556