필터 지우기
필터 지우기

How can i generate random distributed bar objects

조회 수: 1 (최근 30일)
muhammad ahmad
muhammad ahmad 2018년 10월 23일
답변: muhammad ahmad 2018년 10월 23일
I need to generate some random bar objects to test my collision avoidance algorithm hoe can I do that?

답변 (3개)

KSSV
KSSV 2018년 10월 23일
S = [0 0 ; 1 0 ; 1 1 ; 0 1]/4 ;
figure
hold on
N = 5 ;
for i = 1:N
C = rand(1,2) ; % center of sqaure
x = S(:,1)+C(1) ;
y = S(:,2)+C(2) ;
patch(x,y,'r')
end
  댓글 수: 5
muhammad ahmad
muhammad ahmad 2018년 10월 23일
I need to this kind of job with cubes as well how ca i do it
KSSV
KSSV 2018년 10월 23일
N = 5 ;
alpha=0.5; % transparency (max=1=opaque)
X = [0 0 0 0 0 1; 1 0 1 1 1 1; 1 0 1 1 1 1; 0 0 0 0 0 1];
Y = [0 0 0 0 1 0; 0 1 0 0 1 1; 0 1 1 1 1 1; 0 0 1 1 1 0];
Z = [0 0 1 0 0 0; 0 0 1 0 0 0; 1 1 1 0 1 1; 1 1 1 0 1 1];
X = X/4 ; Y = Y/4 ; Z = Z/4 ;
figure
hold on
for i = 1:N
C = rand(1,3) ;
x = X + C(1);
y = Y + C(2);
z = Z + C(3);
fill3(x,y,z,C,'FaceAlpha',alpha); % draw cube
end

댓글을 달려면 로그인하십시오.


muhammad ahmad
muhammad ahmad 2018년 10월 23일
Thank you for your contribution one more thing can we extend these cubes in z axixs from 0 to different heights?
  댓글 수: 1
KSSV
KSSV 2018년 10월 23일
N = 5 ;
alpha=0.5; % transparency (max=1=opaque)
X = [0 0 0 0 0 1; 1 0 1 1 1 1; 1 0 1 1 1 1; 0 0 0 0 0 1];
Y = [0 0 0 0 1 0; 0 1 0 0 1 1; 0 1 1 1 1 1; 0 0 1 1 1 0];
Z = [0 0 1 0 0 0; 0 0 1 0 0 0; 1 1 1 0 1 1; 1 1 1 0 1 1];
X = X/4 ; Y = Y/4 ; Z = Z/4 ;
figure
hold on
for i = 1:N
C = rand(1,3) ;
x = X ;
y = Y ;
z = Z + i;
fill3(x,y,z,C,'FaceAlpha',alpha); % draw cube
end
Thank you officially for accepting this answer.

댓글을 달려면 로그인하십시오.


muhammad ahmad
muhammad ahmad 2018년 10월 23일
well this code is stacking cubes along z-axis but I didn't mean that I was asking about the extension of individual cube simply i just want to do the same work as scattere3(x,y,z) does and generate the random dots instead of dots i want to plot bars or cubes

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by