MATLAB Answers

circles moving with linear velocity

3 ビュー (過去 30 日間)
faiza gul
faiza gul 2019 年 5 月 10 日
回答済み: Walter Roberson 2019 年 5 月 10 日
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];
Velocity =[0.18 0.15]; %velocity can be any constant value
for k=1:numel(xobs)
fill(xobs(k)+robs(k)*cos(70),yobs(k)+robs(k)*sin(0),[1 0 0]);
hold on
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 件のコメント

Walter Roberson
Walter Roberson 2019 年 5 月 10 日
Why did you go backwards from the much more controlable code I gave you in your other question?


回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 5 月 10 日
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.

  0 件のコメント



Community Treasure Hunt

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

Start Hunting!

Translated by