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
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 CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by