Info
此问题已关闭。 请重新打开它进行编辑或回答。
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)
2 次查看(过去 30 天)
显示 更早的评论
此 个问题 已被 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 个评论
Rik
2021-4-28
What issues are you having in implementing that? Do you have issues generating random numbers? Or detecting if the points are invalid?
Walter Roberson
2021-4-28
And no one helped me till now.
Then Paul and I are "no one" ???
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!