During the moving random points, I don't see animation, instead I see re scattering?
5 views (last 30 days)
Please, would you tell me why the random points is not moving, they just re-scatter in each time step, while I am trying to animate thm or make them moving continously. if you have any help I would appreciat it , thanks in advance
% Initial direction/velocity of the points
velocity = 28.8/3.6;
% Create random starting locations within the circle
direction = rand(npts, 1) * 2 *pi;
theta = rand(npts, 1) * 2*pi;
g = 0.5 * radius + 0.5 * radius * rand(npts,1);
XY = [X_x ,Y_y];
DX = [cos(direction(:)) .* velocity,sin(direction(:)) .* velocity];
XYnew = XY + DX;
% Plot the dots as black markers
hdots = plot(XYnew(:,1), XYnew(:,1),'Marker', '.','Color', 'k','LineStyle', 'none','MarkerSize', 12);
% Plot the circle as a reference
t = linspace(0, 2*pi, 100);
plot(radius * cos(t) + center(1),radius * sin(t) + center(2))
% Update the dot plot to reflect n ew locations
set(hdots, 'XData', XY(:,1), 'YData', XY(:,2))
% Force a r edraw
Walter Roberson on 2 Jun 2022
Your code builds new random points each time step, and directly jump the old points to the new position.
In order to have them visibly move to new positions, you would need to generate intermediate positions and move the points to through those positions.