Plotting a circle always around a moving point

25 ビュー (過去 30 日間)
Rudrashis  Majumder
Rudrashis Majumder 2019 年 3 月 4 日
I need to plot a circle whose center is a moving point. The point is moving with its path being plotted using "animatedline". However, I want to show only the current circle centering the point at a particular instant and the previous circles are to be cleared. Please help.

採用された回答

KSSV
KSSV 2019 年 3 月 4 日
x = linspace(0,2*pi) ;
y = cos(x) ;
R = 0.1 ;
for i = 1:length(x)
plot(x(1:i),y(1:i))
axis([0 6 -2 2])
hold on
xc = x(i)+R*cos(x) ;
yc = y(i)+sin(x) ;
plot(xc,yc,'r')
hold off
drawnow
pause(0.1)
end
Read about comet.

その他の回答 (1 件)

Jos (10584)
Jos (10584) 2019 年 3 月 4 日
Adapted from the help of animatedline:
numpoints = 10000;
x = linspace(0,4*pi,numpoints);
y = sin(x);
pc = [-.1 -.1 .2 .2] ; % position of circle
figure
h = animatedline;
hc = rectangle('Position', [x(1) y(1) 0 0]+pc,'Curvature',1, 'FaceColor','r') ; % draw circle
axis([-pi,5*pi,-1.5,1.5])
for k = 1:numpoints
addpoints(h,x(k),y(k))
set(hc,'Position', [x(k) y(k) 0 0] + pc) ; % adjust position of circle
drawnow update
end
  1 件のコメント
Rudrashis  Majumder
Rudrashis Majumder 2019 年 3 月 4 日
Thank you very much.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by