wx
wy
wz
running=true; //First give the variables some initial values // setballs ballx[0]=Array(.5,.5,0); ballx[1]=Array(.5,-.5,0); ballx[2]=Array(-.5,.5,0); ballx[3]=Array(-.5,-.5,0); ballx[4]=Array(0,0,.5); ballx[5]=Array(0,0,-.5); jx=0; //Calculate the principal moments jy=0; jz=0; for(i=0;i<4;i++){ jx+=ballx[i][1]*ballx[i][1]+ballx[i][2]*ballx[i][2]; jy+=ballx[i][0]*ballx[i][0]+ballx[i][2]*ballx[i][2]; jz+=ballx[i][0]*ballx[i][0]+ballx[i][1]*ballx[i][1]; } transform[0]=Array(0,0,-1); //initialise the transform to show the rotor edge-on transform[1]=Array(0,1,0); transform[2]=Array(1,0,0); for(i=0;i
//Transform cworld to cgyro in gyro axes cworld=Array(ballt[4][2],0,-ballt[4][0]); cgyro=Array(0,0,0); for (ii=0;ii<3;ii++){ for(jj=0;jj<3;jj++){ cgyro[ii]+=transform[jj][ii]*cworld[jj]; } } dwx=((jy-jz)*wy*wz + cgyro[0])/jx; dwy=((jz-jx)*wz*wx + cgyro[1])/jy; dwz=((jx-jy)*wx*wy + cgyro[2])/jz; wx+=dwx*dt; wy+=dwy*dt; wz+=dwz*dt; omega(wx,wy,wz); //rotate and show the balls document.inputs.posx.value = wx; document.inputs.posy.value = wy; document.inputs.posz.value = wz; if(running==true){setTimeout('StepModel()',5);}