how to make different points movable in MATLAB

I wanted help in making different point moving with constant velocity. All points should be moving at constant speed.

 Réponse acceptée

Walter Roberson
Walter Roberson le 2 Fév 2019

0 votes

Use scatter and record the handle . Loop updating the XData and YData properties of the handle and drawnow()

6 commentaires

h=msgbox('Select Obstacles using the Left Mouse button,to select the last obstacle use the Right button');
xlabel('Select Obstacles using the Left Mouse button,to select the last obstacle use the Right button','Color','blue');
uiwait(h,10);
if ishandle(h) == 1
delete(h);
end
while but == 1
[xval,yval,but] = ginput(1);
xval=floor(xval);
yval=floor(yval);
plot(xval+0.5+yval+0.5,'ro');
end
I have used this code for creating random points( red circles) Now I want them to be moving with consatnt velocity ,like creating them random particles.
h=msgbox('Select Obstacles using the Left Mouse button,to select the last obstacle use the Right button');
xlabel('Select Obstacles using the Left Mouse button,to select the last obstacle use the Right button','Color','blue');
uiwait(h,10);
if ishandle(h) == 1
delete(h);
end
count = 0;
xvals = []; yvals = [];
while true
[xval,yval,but] = ginput(1);
if isempty(xval); break; end
count = count + 1;
xvals(count) = floor(xval);
yvals(count) = floor(yval);
end
dx = randn(1, count); %potentially a different velocity for each particle
dy = randn(1, count);
pointsize = 10;
h = scatter(xvals, yvals, pointsize, 'r');
for step = 1 : 100
xvals = xvals + dx;
yvals = yvals + dy;
set(h, 'XData', xvals, 'YData', yvals);
drawnow();
end
Thank you so much Walter.
How can I make these points move with specific velocity and direction with this equation
Xobs_new= Xobs+ Vobs* cos(theta)
Ynew_obs= Yobs+Vobs*sin(theta)
Vobs and theta are undefined. Is theta intended to be atan2(y, x) ?
Since I want to make the points moving with constant velocity, Vobs can be fixed number. Secondly yes its a theta, direction for particels/point to move forward.
Walter Roberson
Walter Roberson le 6 Fév 2019
Modifié(e) : Walter Roberson le 6 Fév 2019
%need _some_ Vobs and theta
theta = rand() * 2 * pi;
Vobs = rand() * 10;
h=msgbox('Select Obstacles using the Left Mouse button,to select the last obstacle use the Right button');
xlabel('Select Obstacles using the Left Mouse button,to select the last obstacle use the Right button','Color','blue');
uiwait(h,10);
if ishandle(h) == 1
delete(h);
end
count = 0;
xvals = []; yvals = [];
while true
[xval,yval,but] = ginput(1);
if isempty(xval); break; end
count = count + 1;
xvals(count) = floor(xval);
yvals(count) = floor(yval);
end
dx = Vobs * cos(theta);
dy = Vobs * sin(theta);
pointsize = 10;
h = scatter(xvals, yvals, pointsize, 'r');
for step = 1 : 100
xvals = xvals + dx;
yvals = yvals + dy;
set(h, 'XData', xvals, 'YData', yvals);
drawnow();
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by