The stick is portrayed by a ball at each end.
running=true; //First give the variables some initial values L1=.5; // length of string L2=1; // length of the stick x1=.1; // initial displacements x2=.3; // try out eigenvectors xcog=(x1+x2)/2; th2=(x2-x1)/L2; y1=-L1; y2=-L1-L2; J=L2*L2/12; // MI of stick vx1=0; vx2=0; vcog=0; vth2=0; dt = .01; //Make this smaller for better accuracy Moveball(ball0,0,0,0); //suspension point StepModel(); //Start the simulation running
th1=x1/L1; // work out angles th2=(x2-x1)/L2; acccog= -g*th1; // acceleration of CoG accth2= g*(th1-th2)*L2/(2*J); vcog+=acccog*dt; vth2+=accth2*dt; xcog+=vcog*dt th2+=vth2*dt; x1=xcog-th2*L2/2; x2=xcog+th2*L2/2; Moveball(ball1,x1,y1,0); Moveball(ball2,x2,y2,0); if(running){setTimeout('StepModel()',10);}