function [posx, posy]=computetraj(drawcodes,ink); [numcases, numcode]= size(drawcodes); maxtime = size(drawcodes,2)/4; dcodes = .001*drawcodes.*ones(numcases,numcode)*20; stiffu = dcodes(:,1:maxtime); stiffd = dcodes(:,1+maxtime:2*maxtime); stiffl = dcodes(:,1+2*maxtime:3*maxtime); stiffr = dcodes(:,1+3*maxtime:4*maxtime); endu = -25*ones(numcases,1); endd = 53*ones(numcases,1); endl = -25*ones(numcases,1); endr = 53*ones(numcases,1); % start with zero velocity from the equilibrium position of the initial spring stiffnesses velx = zeros(numcases,maxtime); posx = zeros(numcases,maxtime); posx(:,1)= (endl.*stiffl(:,1) + endr.*stiffr(:,1)) ./ (stiffl(:,1) + stiffr(:,1)); vely = zeros(numcases,maxtime); posy = zeros(numcases,maxtime); posy(:,1)= (endu.*stiffu(:,1) + endd.*stiffd(:,1)) ./ (stiffu(:,1) + stiffd(:,1)); % At each subsequent time step, the spring stiffnesses specify an acceleration, % which is converted into a velocity, which is converted into a position. for t=2:maxtime if varyvisc==1 viscosities = .15 + .3*(ink(:,t+2)-.5); %%first 2 are for type of ink. end; accx = (stiffl(:,t).*(endl-posx(:,t-1)) + stiffr(:,t).*(endr-posx(:,t-1)))./masses; velx(:,t) = (1-viscosities).*velx(:,t-1)+accx; posx(:,t) = posx(:,t-1)+velx(:,t); accy = (stiffu(:,t).*(endu-posy(:,t-1)) + stiffd(:,t).*(endd-posy(:,t-1)))./masses; vely(:,t) = (1-viscosities).*vely(:,t-1)+accy; posy(:,t) = posy(:,t-1)+vely(:,t); end; end;