how do I make dots move within a circle?
3 views (last 30 days)
Show older comments
How do I make certain dots move within a circle? While other dots move outside the circle?
4 Comments
TADA
on 23 May 2022
Edited: TADA
on 23 May 2022
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
Answers (0)
See Also
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!