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)
조회 수: 1 (최근 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!