0

I read some related discussion:

How to add dynamic data labels inside of .avi animation?

Text Animation with MATLAB

These examples are much difficult than mine so I cannot quite understand how to solve my problem.


I made the following animation, I just want to

  1. add the label "{E}" under the "center blue point"
  2. add the label "{P}" near the "small blue circle", which rotate the "center blue point" and inside the "middle blue circle".
  3. add the label "{S}" near the "small red *", which rotate the "big blue circle".

Of course labels {P} and {S} should closely follow each corresponding object.

How could I do that? ...

clear all;
close all;
clc


%% time specifications
stoptime = 8;
fs = 50;
dt = 1/fs;
t = (0:dt:stoptime)';

N = size(t,1); 
%% 
vx(:,1) = 0;vy(:,1) = 15;vz(:,1) = 0;
ux(:,1) = 0 ;uy(:,1) = 3 ;uz(:,1) = 0;

%% angular velocity
Ix = 3,5;
Iz = 1;
w = .1; % w_L
wp = ( (Ix-Iz)/Iz )*w*(2)^.5


%% 
for k = 2:N

vx(:,k) = cos(w*(k-1))*vx(:,1) - sin(w*(k-1))*vy(:,1) + 0*vz(:,1);
vy(:,k) = sin(w*(k-1))*vx(:,1) + cos(w*(k-1))*vy(:,1) + 0*vz(:,1);
vz(:,k) = 0*vx(:,k-1) + 0*vy(:,k-1) + 1*vz(:,k-1);

ux(:,k) = cos((w+wp)*(k-1))*ux(:,1) - sin((w+wp)*(k-1))*uy(:,1) + 0*uz(:,1) + vx(:,k);
uy(:,k) = sin((w+wp)*(k-1))*ux(:,1) + cos((w+wp)*(k-1))*uy(:,1) + 0*uz(:,1) + vy(:,k);
uz(:,k) = 0*ux(:,1) + 0*uy(:,1) + 1*uz(:,1) + vz(:,k);    




o = [0;0];
xline = [vx(:,k);o(1,1)];
yline = [vy(:,k);o(2,1)];
xline1 = [vx(:,k);ux(:,k)];
yline1 = [vy(:,k);uy(:,k)];

figure(1)
ang=0:0.01:2*pi; 
xp=15*cos(ang);
yp=15*sin(ang);  
xp1=3*cos(ang)+vx(:,k);
yp1=3*sin(ang)+vy(:,k);

plot(xp,yp,'c--'); hold on
plot(xp1,yp1); hold on
plot(0,0,'.'); hold on
plot(xline,yline); hold on 
plot(xline1,yline1); hold on 
plot(vx(:,k),vy(:,k),'bo');
plot(ux(:,k),uy(:,k),'r*'); hold on
axis([-25 25 -25 25]);
axis equal
axis manual
pause(.1);
hold off
end

enter image description here

Sorry, I have no idea to upload my animation video. That is just the picture of it.

Community
  • 1
  • 1
sleeve chen
  • 221
  • 1
  • 11

1 Answers1

1

You can do this with the text function.

tOff = [1,1];   %%% (text offset)
plot(xp,yp,'c--'); hold on
plot(xp1,yp1); 
plot(0,0,'.'); 
text (tOff, tOff, sprintf('(%d,%d)', 0, 0)); %%%
plot(xline,yline); 
plot(xline1,yline1); 
plot(vx(:,k),vy(:,k),'bo'); 
text (vx(:,k)+tOff,vy(:,k)+tOff, sprintf('(%1.3d,%1.3d)', vx(:,k),vy(:,k))); %%%
plot(ux(:,k),uy(:,k),'r*'); 
text (ux(:,k)+tOff,uy(:,k)+tOff, sprintf('(%1.3d,%1.3d)', vx(:,k),vy(:,k))); %%%
axis([-25 25 -25 25]);
axis equal
axis manual
pause(.1);
hold off

This is the same code as yours above, except with some additions, marked with %%%. Also note, hold on only needs to be specified once, and will apply until hold off occurs (or the figure is destroyed). (I removed the superfluous hold on instructions in your code above).

enter image description here

Tasos Papastylianou
  • 21,371
  • 2
  • 28
  • 57