circles moving with linear velocity

3 visualizzazioni (ultimi 30 giorni)
passioncoding
passioncoding il 10 Mag 2019
Risposto: Walter Roberson il 10 Mag 2019
I have made some circles with fill command I want them to move them with some velocity.(linearly)
xobs=[7.5 5.1];
yobs=[2.1 8.3];
robs=[0.3];
Velocity =[0.18 0.15]; %velocity can be any constant value
theta=linspace(0,2*pi,100);
for k=1:numel(xobs)
fill(xobs(k)+robs(k)*cos(70),yobs(k)+robs(k)*sin(0),[1 0 0]);
hold on
end
hold off
I need these circles to be moving linearly. I want to make them dynamic. Like moving obstacles. These circles are moving (moving obstacles)
  1 Commento
Walter Roberson
Walter Roberson il 10 Mag 2019
Why did you go backwards from the much more controlable code I gave you in your other question?

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 10 Mag 2019
Code attached. This is relatively minor alterations to the code I gave you in #457575 .
For each particle, it determines a random number of speed changes (in this implementation, really acceleration changes, but that could be changed without much difficulty.) At that many times throughout the iterations (frame rate times video duration) it schedules new random velocities. Then it interpolates the velocity for every frame for that particle, resulting in a per-frame x and y velocity list for every particle.
Then the iteration loop is barely unchanged from my previous code, except that instead of using a constant velocity that is different for each particle, it recalls the per-frame per-particle velocity previously calculated. So as the frames go on, particles accelerate and decelerate and change direction.
It would be equally valid to instead have each particle start with a velocity, and to choose the new velocity as you go, with it perhaps randomly selecting a new velocity if some condition occurs (e.g., "hitting" something), or with it randomly selecting a new velocity if a random event occurs. The difference would be that you would use one velocity per particle (like in my previous version) but that in the "for iterations" loop you would do whatever detection or random selection you wanted and update the particle velocity and then move the particle.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by