Trying to simulate an object plunging into atmosphere. It seems to work, until the velocity falls past terminal velocity... down to zero... and then back up!
Something must be wrong with how I am applying drag? I've looked at the code so long, I've managed to confuse myself.
Here I set variables/constants:
Mass = 5; //Object Mass
Radius = 7; //Radius of the blunt end facing the air stream (too sensitive!!!)
Area = power(Radius,2)*pi; //The total area of the blunt end facing the air stream
Gravity = 9.8; //Earth
DragCoeff = 1.61;
Velocity = 10000; //Initial velocity straight down (vector needs to be added)
Acceleration = Gravity * (1/Mass); //this is acceleration FORCE... subtract drag from this
Altitude = 100000; //initial altitude(meters) (atmosphere "begins" at 100Km)
Then, in the main loop of the program: (note, delta_time is provided by the system in microseconds from the last execution of the loop)
d_time = delta_time / 1000000; //Convert delta_time to seconds
AirDensity = 1.07* power(2.718,-.00005*Altitude); //How dense is the air right now?
TermVel = sqrt(2 * Mass * Gravity / AirDensity * Area * DragCoeff); //Terminal Velocity at our altitude
Velocity = Velocity + Acceleration * d_time; //Acceleration added
Drag = 0.5 * AirDensity * sqr(Velocity)* DragCoeff * Area; //Drag calculated
Velocity = Velocity - (clamp(Drag, 0, TermVel) * d_time); //Drag subtracted
Altitude = Altitude - Velocity * d_time; //Update the position
Thanks ever so much for your kind help in understanding what I've done wrong here.
SS
Edit: Thanks, Jason... I think I have the correct changes made... but my mass of "5" was causing it to behave really poorly.... the velocity went way negative... so I increased the mass significantly, and it seems to behave better... I will explore it a bit more.
Does it look like I have it right?
Thank you again, ever so much.
SS