how do I make dots move within a circle?
3 ビュー (過去 30 日間)
古いコメントを表示
How do I make certain dots move within a circle? While other dots move outside the circle?
4 件のコメント
TADA
2022 年 5 月 23 日
編集済み: TADA
2022 年 5 月 23 日
something like that maybe?
% radii
r = 1;
rInner = r - 0.1;
rOuter = r + 0.1;
% theta
t = linspace(0, 2*pi);
% animation settings
frameshift = 0.05;
fps = 24;
frameInterval = 1/fps;
numFrames = 500;
% circle data
x = r*cos(t);
y = r*sin(t);
% animation loop
for i = 1:numFrames
% plot the circle
plot(x,y);
axis equal;
hold on;
% calculate the inner/outer dots positions
xout = (rOuter)*cos(t + i * frameshift);
yout = (rOuter)*sin(t + i * frameshift);
xin = (rInner)*cos(t - i * frameshift);
yin = (rInner)*sin(t - i * frameshift);
% plot inner/outer dots
plot(xout, yout, '.');
plot(xin, yin, '.');
% pause until next frame
pause(frameInterval);
% to clear the plot next iteration
hold off;
end
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Animation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!