function [rn,tt] = TraceStep(r,tt,data,stepsize,scansize,scannum,maxiter,pixelsize);

    for a=1:maxiter;    

    	% use the last tangent to guess the position
	    % of the next point distance stepsize away. 
        rn = r+tt*stepsize;
        %plot(rn(1)+.5,rn(2)+.5,'w.');
    	

	    % compute a normal to the tangent     
        normal = [tt(2),-tt(1)];

    	% and project the data onto a segment defined
	    % by scanvec. scanvec is a vector with the 
        % distance at which the the data will be interpolated
	    % on the normal...
        scanvec = ((-scannum):scannum)/scannum*scansize;
    
	    % get the length of this vector 
        sizescan = max(size(scanvec));
       
        % now make the point at which we wish to interp 
        % the data. They are at the guessed position normal
	    % to the curve with the spacing given by scanvec.
        rscanvec = zeros(sizescan,2);
        rscanvec = scanvec'*normal + ones(sizescan,1)*rn;

	    % now we do the interpolation onto these point producing
	    % a vector of z values
	    z = interpolate_im3(data,rscanvec/pixelsize);

	    % Now we compute the center of mass by multiplying these
	    % z values (the mass) by their spacial positions
        rnn = z'*rscanvec;

	    % and dividing by the sum of the z's or the total mass   
        rn = rnn/sum(z);
	    % to give a new guess for the position of the curve...
	    % but this new point does not lie at the right distance
	    % so we will compute the tangent only... which in turn
	    % will update the the r guess... then we iterate to improve
	    % the guess
        tt = (rn-r)/norm(rn-r);
	    rn = r+tt*stepsize;
    end;    
    
    
    % make the next point equal to the guess... which is now pretty 
    % good since we interated it...
  
