Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. %function anim = animation(t,@y,@z)
  2. function [anim] = animation(t,y,z)
  3. y = y(t); % y coordinates of the two bodies
  4. z = z(t); % z coordinates of the two bodies
  5.  
  6. % create two circles:
  7. r1=0.2; % radius circle 1
  8. r2=0.1; % radius circle 2
  9. x=(0:0.01*pi:2*pi);
  10.  
  11. c1 = [r1*cos(x); r1*sin(x)]; % circle 1
  12. c2 = [r2*cos(x); r2*sin(x)]; % circle 2
  13.  
  14. hold on
  15. h1 = fill(c1(1,:),c1(2,:),'b'); % fill circle 1
  16. h2 = fill(c2(1,:),c2(2,:),'r'); % fill circle 2
  17.  
  18. % create the connecting line
  19. l = line([y(1,1) y(1,2)], [z(1,1) z(1,2)], 'color','c');
  20.  
  21. % create the axes
  22. axis ([1.25*(min(y(:,1))) 1.25*(max(y(:,1))) 1.25*(min(z(:,1))) 1.25*(max(z(:,1)))])
  23. axis('square')
  24. xlabel('y-axis')
  25. ylabel('z-axis')
  26. tic
  27.  
  28. % plotting the animation
  29. for k = 1:length(t)
  30. set(h1,'xdata', c1(1,:)+y(k,1),'ydata',c1(2,:)+z(k,1));
  31. set(h2,'xdata', c2(1,:)+y(k,2),'ydata',c2(2,:)+z(k,2));
  32. set(l, 'xdata',[y(k,1), y(k,2)],'ydata',[z(k,1), z(k,2)]);
  33.  
  34. drawnow;
  35. while toc < t(k)
  36. end
  37. end
  38. toc
  39. end
  40.  
  41. %end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement