Help with animation of vector
7 views (last 30 days)
Show older comments
I have a script that utilizes a separate function that plots an arrow between the center of a circle and an object rotating around it. When I set the handles to animate it, I cannot get the arrowhead itself to be plotted. Is there any ideas?
% Script file for animating the circular motion of a bead
% -------------------------------------------
theta = linspace(0,12*pi,1000);
x=cos(theta); % generate x and y-coordinate
y=sin(theta); % of the bead along the path
hbead = plot(x(1),y(1),'o', 'markersize',8); % draw the bead at the initial
hold on
r = plot_arrow(0,0,x(1),y(1));
axis([-2 2 -2 2]); axis('square');
plot(x,y);
for k=1:length(theta) % cycle through all positions
set(hbead,'xdata',x(k),'ydata',y(k))
set(r(1),'xdata',[0;x(k)],'ydata',[0;y(k)]);
set(r(2),'xdata',x(k),'ydata',y(k));
drawnow
end
The function for drawing the arrows has an output of :
den = x2 - x1 + eps; % make sure no devision by zero occurs
teta = atan( (y2-y1)/den ) + pi*(x2<x1) - pi/2; % angle of arrow
cs = cos(teta); [0,0] % rotation matrix
ss = sin(teta);
R = [cs -ss;ss cs];
line_length = sqrt( (y2-y1)^2 + (x2-x1)^2 ); % sizes
head_length = min( line_length*alpha,max_length )*1.5;
head_width = min( line_length*beta,max_length )*1.5;
x0 = x2*cs + y2*ss; % build head coordinats
y0 = -x2*ss + y2*cs;
coords = R*[x0 x0+head_width/2 x0-head_width/2; y0 y0-head_length y0-head_length];
h1 = plot( [x1,x2],[y1,y2],'k' );
h2 = patch( coords(1,:),coords(2,:),[0 0 0] )
output = [h1 h2]
0 Comments
Answers (0)
See Also
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!