During the moving random points, I don't see animation, instead I see re scattering?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
omar th
el 2 de Jun. de 2022
Comentada: omar th
el 8 de Jun. de 2022
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
npts=2;center=[0 0];radius=1000;
% Initial direction/velocity of the points
velocity = 28.8/3.6;
% Create random starting locations within the circle
Totaltime =10;
direction = rand(npts, 1) * 2 *pi;
for Timestep=1:1:Totaltime
theta = rand(npts, 1) * 2*pi;
g = 0.5 * radius + 0.5 * radius * rand(npts,1);
X_x=center(1)+g.*cos(theta);
Y_y=center(2)+g.*sin(theta);
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);
hold on
axis equal
% 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
drawnow
pause (1)
end
2 comentarios
Respuesta aceptada
Walter Roberson
el 2 de Jun. de 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.
3 comentarios
Walter Roberson
el 3 de Jun. de 2022
Every major step you generate notably different coordinates (for example, current location of people sampled every ten minutes... when they might be in a car or elevator, so there might be fair jumps in coordinates.)
Your current code generates the new coordinates, and then sets the graphics to be the new coordinates directly.
If your sampling period was small compared to the expected maximum change, then the method you use would work to animate the positions.
But your random movement is large compared to the time step, and your current code would make visible jumps instead of smooth jumps.
You have two options:
- you can reduce the maximum movement per time step so everything becomes smooth. If you do this, it would probably be a good idea to model a remembered velocity so that you can get points moving in straight lines instead of brownian motion
- or, you could generate the jumps like you do, but then inside the time loop have another loop that draws each point moving a portion of the way between the old locations and the new locations. For example divide the change in coordinates by 10 and take 10 graphic steps moving 1/10 of the way each time.
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Performance en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!