Guest User

Untitled

a guest
Aug 19th, 2014
419
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. M = csvread('hilbert.csv');
  2. x = abs(M(:,1)');
  3. y = abs(M(:,2)');
  4. % calculate intermediate points so that we get an approximate equal spaced
  5. % line of points
  6. n = length(x);
  7. xi = []; yi = [];
  8.  
  9. stepsize = 0.3;%new stepsize
  10.  
  11. original_stepsize = sqrt((x-[x(2:end),x(1)]).^2+(y-[y(2:end),y(1)]).^2);%os(i) = d(i,i+1)
  12. for i=1:n
  13.     t = linspace(0,1,original_stepsize(i)/stepsize);
  14.     t = t(1:end-1);
  15.     if i ~= n
  16.         xi = [xi, x(i)*(1-t)+x(i+1)*t];
  17.         yi = [yi, y(i)*(1-t)+y(i+1)*t];
  18.     else %i==n
  19.         xi = [xi, x(n)*(1-t)+x(1)*t];
  20.         yi = [yi, y(n)*(1-t)+y(1)*t];
  21.     end
  22. end
  23. %% animation
  24. h = figure(1);
  25. set(h, 'Position', [100, 100, 600, 600]);
  26. filename = 'curve_shortening.gif';
  27. flag_first = 1;
  28.  
  29. timestepsize = 0.5;
  30. totalit = 0;%total nubmer of iterations
  31. for k=1:300
  32.    
  33. plot(xi,yi,'-')
  34. text(50,275,[num2str(totalit),' ',num2str(k)])
  35. axis([-10,265,-10,265]);
  36.  
  37. %calculate first and second derivatives
  38.  
  39.     for l=1:k^0.8
  40.         ddxi = [xi(2:end),xi(1)]-2*xi+[xi(end),xi(1:end-1)];
  41.         ddyi = [yi(2:end),yi(1)]-2*yi+[yi(end),yi(1:end-1)];
  42.         xi = xi+timestepsize*ddxi;
  43.         yi = yi+timestepsize*ddyi;
  44.         totalit = totalit+1;
  45.  
  46.         if mod(k,1) == 0
  47.             r = randi(length(xi),1,round(length(xi)*0.0005));%remove 0.05percent of points
  48.             xi(r) = [];
  49.             yi(r) = [];
  50.         end
  51.  
  52.     end
  53. %capture image    
  54.     if mod(k,2) == 1
  55.         set(gcf,'color',[1 1 1]);%white background
  56.         axis off
  57.         drawnow
  58.         frame = getframe(1);
  59.         im = frame2im(frame);
  60.         [imind,cm] = rgb2ind(im,256);
  61.         if flag_first == 1;
  62.             imwrite(imind,cm,filename,'gif', 'Loopcount',inf, 'DelayTime',0.05);
  63.             flag_first = 0;
  64.         else
  65.             imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',0.05);
  66.         end
  67.     end
  68.  
  69. %pause(0.1)
  70.  
  71. end
RAW Paste Data