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.
1 件のコメント
このコメントへの直接リンク
https://jp.mathworks.com/matlabcentral/answers/461414-circles-moving-with-linear-velocity#comment_704042
このコメントへの直接リンク
https://jp.mathworks.com/matlabcentral/answers/461414-circles-moving-with-linear-velocity#comment_704042
サインインしてコメントする。