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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!