circles moving with linear velocity

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

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일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2019년 5월 10일

답변:

2019년 5월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by