-1
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ Would Computational Science be a better home for this question? $\endgroup$ – Qmechanic Feb 8 '18 at 21:52
  • $\begingroup$ You should probably move this question to CompSci as Qmechanic suggests. However, it looks like you're calculating the magnitude drag force incorrectly. Its magnitude depends on the total magnitude of the velocity, not of either component separately. From there, you would resolve it into its components. $\endgroup$ – J. Murray Feb 8 '18 at 22:03
3
$\begingroup$

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:

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ This most certainly is exactly where I went wrong. Thank you very much! I edited my code to reflect the information you have presented here and the program works exactly as expected. For those who might find it helpful, said changes can be viewed in the GitHub repository (github.com/foxyjacob/vulcan). $\endgroup$ – Jacob Marciniec Apr 28 '18 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.