87,901
社区成员
发帖
与我相关
我的任务
分享
genTrack = function(dragFn, d, m, u, theta, y0)
{
var g = 32.2, // acceleration due to gravity (9.8 m/s)
rho = 0.074, // density of air (1.225 kg/m^3)
phi = 3.158E-5, // atm density scale factor (9.626E-6 /m)
Cd, decel, H, // drag coeff, deceleration, altitude factor
x = 0, // range
y = y0 || 7, // height
V = u || 1680, // magnitude of velocity vector
theta0 = theta || 40,
vx = V*Math.cos(Math.PI*theta/180.0), // x vel component
vy = V*Math.sin(Math.PI*theta/180.0),
ax, ay, // acceleration components
dt = 0.02, // time step size
trackData;
trackData = [x/3, y/3];
while (y>0) // stop track when bullet hits ground
{
Cd = dragFn(V, d);
H = Math.exp(-phi*y);
decel = Cd*rho*H*Math.PI*d*d/(m*8);
ax = -decel*V*vx;
ay = -g -decel*V*vy;
vx = vx + ax*dt;
vy = vy + ay*dt;
V = Math.sqrt(vx*vx+vy*vy);
x = x + vx*dt + ax*dt*dt/2;
y = y + vy*dt + ay*dt*dt/2;
trackData.push(x/3, y/3);
}
return trackData;
};