Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %function anim = animation(t,@y,@z)
- function [anim] = animation(t,y,z)
- y = y(t); % y coordinates of the two bodies
- z = z(t); % z coordinates of the two bodies
- % create two circles:
- r1=0.2; % radius circle 1
- r2=0.1; % radius circle 2
- x=(0:0.01*pi:2*pi);
- c1 = [r1*cos(x); r1*sin(x)]; % circle 1
- c2 = [r2*cos(x); r2*sin(x)]; % circle 2
- hold on
- h1 = fill(c1(1,:),c1(2,:),'b'); % fill circle 1
- h2 = fill(c2(1,:),c2(2,:),'r'); % fill circle 2
- % create the connecting line
- l = line([y(1,1) y(1,2)], [z(1,1) z(1,2)], 'color','c');
- % create the axes
- axis ([1.25*(min(y(:,1))) 1.25*(max(y(:,1))) 1.25*(min(z(:,1))) 1.25*(max(z(:,1)))])
- axis('square')
- xlabel('y-axis')
- ylabel('z-axis')
- tic
- % plotting the animation
- for k = 1:length(t)
- set(h1,'xdata', c1(1,:)+y(k,1),'ydata',c1(2,:)+z(k,1));
- set(h2,'xdata', c2(1,:)+y(k,2),'ydata',c2(2,:)+z(k,2));
- set(l, 'xdata',[y(k,1), y(k,2)],'ydata',[z(k,1), z(k,2)]);
- drawnow;
- while toc < t(k)
- end
- end
- toc
- end
- %end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement