I have created random obstacles in MATLAB, (they are user acquired) now I am trying to make some obstacles randomly moving.
I Know that, in every iteration value of some obstacle be updated by adding some threshold valueto it.
But I am getting how to write up in code.
Kindly help me

12 commentaires

Geoff Hayes
Geoff Hayes le 2 Jan 2019
faiza - you may want to provide more details or show some code so that we can get a better idea of what you are attempting to do. How are you storing the obstacles? Does each obstacle have a different speed? etc.
passioncoding
passioncoding le 2 Jan 2019
Modifié(e) : Geoff Hayes le 3 Jan 2019
pause(2);
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+.5,yval+.5,'ro')
end
The first part is just the message the allows user to get values on graph.
Second part, takes the value of x and y and create as many as red circles till left button is not pressed. These red circles are my obstacles in MATLAB.
Now I want that, these static obstacles moves with certain speed (like making them random) not necessarily all points should be moving only some of them.
I hoped I expalined well.
Geoff Hayes
Geoff Hayes le 3 Jan 2019
faiza - so you will probably want to save the handle of each "plotted" obstacle to an array and then decide (somehow) which obstacle is randomly chosen to move in some direction with some speed (how will you determine this?).
passioncoding
passioncoding le 3 Jan 2019
That exactly I am not getting, like how to make some points moving(dynamic) and some static.
If all the points become dynamic (all are moving) then it is also okay.
Geoff Hayes
Geoff Hayes le 3 Jan 2019
how do you want to decide which points are moving and which aren't? this seems like an implementation detail...
passioncoding
passioncoding le 3 Jan 2019
Modifié(e) : Geoff Hayes le 4 Jan 2019
a = [41.50, -70.95];
b = [ 41.80 , -70.50];
% straight line function from a to b
func = @(x)a(2) + (a(2)-b(2))/(a(1)-b(1))*(x-a(1));
% determine the x values
x = linspace(a(1),b(1),50);
% determine the y values
y = func(x);
% create the figure
figure;
% get a handle to a plot graphics object
hPlot = plot(NaN,NaN,'ro');
% set the axes limits
xlim([min(a(1),b(1)) max(a(1),b(1))]);
ylim([min(a(2),b(2)) max(a(2),b(2))]);
% iterate through each point on line
for k=1:length(x)
% update the plot graphics object with the next position
set(hPlot,'XData',x(k),'YData',y(k));
% pause for 0.5 seconds
pause(0.5);
end
Geoff Hayes I got this part of code from one of your answers regarding animation between two points. I loved and fully understand this code. Since this code follows the staright line of equation Can you help me in making such animation without following line of equation. Like randomly points should be moving in simulaton.
Geoff Hayes
Geoff Hayes le 4 Jan 2019
faiza - but how do you want to choose the new position? Do you randomly choose a direction? And randomly choose a speed?
passioncoding
passioncoding le 4 Jan 2019
I want random a speed for obstacle by which they can move/appear in random directions.
But I want a steady speed through which they can move in my simulation.
Geoff Hayes
Geoff Hayes le 4 Jan 2019
so you want to generate a random speed for each obstacle and then use that speed for the remainder of the simulation...that should be relatively straightforward. You have an array of obstacles and so need to generate an array of speeds for each obstacle (where a speed can be zero for obstacles that are stationary). You will also need an array of directions unless the direction can change for each iteration of the simulation?
passioncoding
passioncoding le 4 Jan 2019
The last part that you mentioned is so correct that exactly I want for my simulation. Like obstacles should move with random speed.
Can you help how should I do this
Pravija Raj
Pravija Raj le 19 Août 2019
Hello Faiza,
I am working with a similar situation. Were you able to figure out the code for your scenario. Please kindly share if you have.
I will explain my problem here. I need to simulate an object that randomly moves in a square area in any direction for a duration of time with a random speed. Can any one help me with the code for this.
passioncoding
passioncoding le 10 Sep 2019
I am working on path planning and avoiding obstacle.

Connectez-vous pour commenter.

 Réponse acceptée

darova
darova le 10 Sep 2019
After long 7 month of training and research i reached a success. Here is what i've achieved
clc,clear
px = 5*rand(10,1); % initial position
py = 5*rand(10,1);
plot(px,py,'.r')
axis([-1 1 -1 1]*20)
hold on
t = 360*rand(size(px)); % initial direction in degree
for i = 1:20 % number of iterations
dx = 0.5*cosd(t); % how fast we move
dy = 0.5*sind(t);
t = t + 90*(0.5-rand(size(px))); % change direction (-45:45) degree
plot([px px+dx]', [py py+dy]') % plot displacement
px = px + dx; % new position
py = py + dy;
h = plot(px,py,'.b'); % plot new position
pause(0.2) % wait
delete(h) % remove new position
% from graph
end
hold off

3 commentaires

passioncoding
passioncoding le 10 Sep 2019
Modifié(e) : passioncoding le 10 Sep 2019
Thats amazing and exceptional. truly good work
darova
darova le 10 Sep 2019
Thank you :)
Pravija Raj
Pravija Raj le 19 Sep 2019
Modifié(e) : Pravija Raj le 19 Sep 2019
Many thanks for your response and really appreciate your work.
Thank you.

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