MATLAB Answers


Help with animation of vector

Asked by Zackery Aranda on 8 Dec 2012

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');
for k=1:length(theta)		% cycle through all positions

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]



No products are associated with this question.

0 Answers

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!