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 件のコメント

Geoff Hayes
Geoff Hayes 2019 年 1 月 2 日
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 2019 年 1 月 2 日
編集済み: Geoff Hayes 2019 年 1 月 3 日
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 2019 年 1 月 3 日
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 2019 年 1 月 3 日
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 2019 年 1 月 3 日
how do you want to decide which points are moving and which aren't? this seems like an implementation detail...
passioncoding
passioncoding 2019 年 1 月 3 日
編集済み: Geoff Hayes 2019 年 1 月 4 日
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 2019 年 1 月 4 日
faiza - but how do you want to choose the new position? Do you randomly choose a direction? And randomly choose a speed?
passioncoding
passioncoding 2019 年 1 月 4 日
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 2019 年 1 月 4 日
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 2019 年 1 月 4 日
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 2019 年 8 月 19 日
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 2019 年 9 月 10 日
I am working on path planning and avoiding obstacle.

サインインしてコメントする。

 採用された回答

darova
darova 2019 年 9 月 10 日

0 投票

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 件のコメント

passioncoding
passioncoding 2019 年 9 月 10 日
編集済み: passioncoding 2019 年 9 月 10 日
Thats amazing and exceptional. truly good work
darova
darova 2019 年 9 月 10 日
Thank you :)
Pravija Raj
Pravija Raj 2019 年 9 月 19 日
編集済み: Pravija Raj 2019 年 9 月 19 日
Many thanks for your response and really appreciate your work.
Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

タグ

質問済み:

2019 年 1 月 2 日

編集済み:

2019 年 9 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by