Create 100 random particles(all the same size) in an empty plot with dimensions (x-axis from -16 to 16) and (y-axis from -16 to 16) and (angle from 0 to 2*pi)
Info
This question is closed. Reopen it to edit or answer.
Show older comments
This question was flagged by Paul Hoffrichter
Create 100 random particles(all the same size) distributed uniformly in an empty plot with dimensions (x-axis from -16 to 16) and (y-axis from -16 to 16) and (angle from 0 to 2*pi). I must avoid the furniture or the obstacles in my map so my map function as below:
xw=-16; xe=16; ys=-16; yn=16; %map dimensions, west, east, south, north
mrx=0.05; mry=0.05; % map resolution {x,y}
[xm ym]=meshgrid(xw:mrx:xe,ys:mry:yn);
m=0*xm.*ym; % initialize the map m
for i=1:size(xm,2)
for j=1:size(ym,1)
r=sqrt(xm(1,i)^2+ym(j,1)^2);
ang=atan2(ym(j,1),xm(1,i))+pi;
if 9<=r && r<=10 && (pi/15<=ang && ang<=29*pi/15)
m(j,i)=1;
elseif 6<=r && r<=7 && ~(pi-pi/6<=ang && ang<=pi+pi/6)
m(j,i)=1;
elseif -14<=xm(1,i) && xm(1,i)<-9 && -2.8<=ym(j,1) && ym(j,1)<=-1.8
m(j,i)=1;
elseif -11<=xm(1,i) && xm(1,i)<-9 && 1.8<=ym(j,1) && ym(j,1)<=2.8
m(j,i)=1;
elseif -14<=xm(1,i) && xm(1,i)<-13 && -2.8<=ym(j,1) && ym(j,1)<=14
m(j,i)=1;
elseif -11<=xm(1,i) && xm(1,i)<-10 && 2.8<=ym(j,1) && ym(j,1)<=11
m(j,i)=1;
elseif -14<=xm(1,i) && xm(1,i)<14 && 14<=ym(j,1) && ym(j,1)<=15
m(j,i)=1;
elseif -11<=xm(1,i) && xm(1,i)<11 && 11<=ym(j,1) && ym(j,1)<=12
m(j,i)=1;
elseif 14<=xm(1,i) && xm(1,i)<15 && -15<=ym(j,1) && ym(j,1)<=15
m(j,i)=1;
elseif -5<=xm(1,i) && xm(1,i)<14 && -15<=ym(j,1) && ym(j,1)<=-14
m(j,i)=1;
elseif 10<=r && r<=16 && 0.95*pi/3.5<=ang && ang<=1.05*pi/3.5
m(j,i)=1;
elseif xm(1,i)<0.98*xw || 0.98*xe<xm(1,i) || ym(j,1)<0.98*ys || 0.98*yn<ym(j,1) % Boundaries
m(j,i)=1;
end
end
end
mesh(xm,ym,m); axis image; view(0, 90); %xlabel('x'); ylabel('y');
11 Comments
the cyclist
on 26 Apr 2021
What's your question?
GHADAH AL-OBAIDI
on 26 Apr 2021
the cyclist
on 26 Apr 2021
Ah, ok. I didn't understand that your code only creates the map.
You need to avoid the yellow area, or the purple/blue area?
GHADAH AL-OBAIDI
on 26 Apr 2021
GHADAH AL-OBAIDI
on 27 Apr 2021
Paul Hoffrichter
on 27 Apr 2021
Duplicate questions (as of 2021-04-27):
GHADAH AL-OBAIDI
on 27 Apr 2021
Rik
on 28 Apr 2021
There are two methods:
- generate random points and reject those that are in an invalid position
- design a procedure that guarantees you will not get any points that are invalid
Which one did you try?
GHADAH AL-OBAIDI
on 28 Apr 2021
Rik
on 28 Apr 2021
What issues are you having in implementing that? Do you have issues generating random numbers? Or detecting if the points are invalid?
Walter Roberson
on 28 Apr 2021
And no one helped me till now.
Then Paul and I are "no one" ???
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!