Skip to content

Instantly share code, notes, and snippets.

@AmarPrabhu
Created January 3, 2014 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmarPrabhu/8235812 to your computer and use it in GitHub Desktop.
Save AmarPrabhu/8235812 to your computer and use it in GitHub Desktop.
Frisbee Modelling in Javascript
function frisbee ()
{
//everything in SI units
var g = -9.81, //deceleration due to gravity
m = 0.175, //mass - change as needed
RHO = 1.23, //density of air
AREA = 0.0568, //area for the frisbee - change as needed
CL0 = 0.1, //lift coefficient parameters
CLA = 1.4,
CD0 = 0.08, //drag coefficient parameters
CDA = 2.72,
ALPHA0 = -4,
x = 0;
//things you can mess with
var y = 1, //height from which you throw the frisbee
vx = 15, //horizontal force when throwing
vy = 5, //vertical force when throwing
deltaT = 0.002, //time split
angleAttack = 3, //angle at which the surface of frisbee meets the air flow
outCSV, //use as necessary based on browser
cl = CL0 + CLA*angleAttack*(Math.PI/180), //lift
cd = CD0 + CDA*(Math.pow(((angleAttack-ALPHA0)*Math.PI/180),2)); //drag
var k = 0;
while(y>0)
{
var deltavy = (RHO*Math.pow(vx,2)*AREA*cl/2/m+g)*deltaT;
var deltavx = -RHO*Math.pow(vx,2)*AREA*cd*deltaT;
vx = vx + deltavx;
vy = vy + deltavy;
x = x + vx*deltaT;
y = y + vy*deltaT;
//increase or decrease data points as necessary
if(k%10 == 0)
{
console.log( x + ',' + y);
//outCSV = outCSV + ',' + x + ',' + y;
}
k++;
}
//alert(outCSV);
}
frisbee();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment