R
X
Y
Z
R
X
Y
Z
S
running=true; //First give the variables some initial values dt = .01; //Make this smaller for better accuracy x=800; //initial position y=0; z=0; vx=0; vy=22,65; vz=0.0; //initial velocity mx=800; //initial position my=20; mz=0; mvx=0; mvy=22.65; mvz=0.0; StepModel(); //Start the simulation running
r=Math.sqrt(x*x+y*y+z*z); //radius accx= -a*x/(r*r*r); //acceleration in x direction accy= -a*y/(r*r*r); // " in y direction accz= -a*z/(r*r*r); // " in y direction vx+=accx*dt; vy+=accy*dt; vz+=accz*dt; x+=vx*dt; y+=vy*dt; z+=vz*dt; Moveball(1, x, y, z); //Move the blue satellite s=Math.sqrt((x-mx)*(x-mx)+(y-my)*(y-my)+(z-mz)*(z-mz)); mr=Math.sqrt(mx*mx+my*my+mz*mz); //radius maccx= -a*mx/(mr*mr*mr)+(x-mx)/s/10; //acceleration in x direction maccy= -a*my/(mr*mr*mr)+(y-my)/s/10; // " in y direction maccz= -a*mz/(mr*mr*mr)+(z-mz)/s/10; // " in y direction mvx+=maccx*dt; mvy+=maccy*dt; mvz+=maccz*dt; mx+=mvx*dt; my+=mvy*dt; mz+=mvz*dt; Moveball(2, mx, my, mz); //Move the missile document.inputs.radius.value = r; //Show the values document.inputs.posx.value = x; document.inputs.posy.value = y; document.inputs.posz.value = z; document.inputs.mradius.value = mr; //Show the values document.inputs.mposx.value = mx; document.inputs.mposy.value = my; document.inputs.mposz.value = mz; document.inputs.sep.value = s; if(running){setTimeout('StepModel()',10);}