Filter löschen
Filter löschen

How can i generate random distributed bar objects

1 Ansicht (letzte 30 Tage)
muhammad ahmad
muhammad ahmad am 23 Okt. 2018
Beantwortet: muhammad ahmad am 23 Okt. 2018
I need to generate some random bar objects to test my collision avoidance algorithm hoe can I do that?

Antworten (3)

KSSV
KSSV am 23 Okt. 2018
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 Kommentare
muhammad ahmad
muhammad ahmad am 23 Okt. 2018
I need to this kind of job with cubes as well how ca i do it
KSSV
KSSV am 23 Okt. 2018
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

Melden Sie sich an, um zu kommentieren.


muhammad ahmad
muhammad ahmad am 23 Okt. 2018
Thank you for your contribution one more thing can we extend these cubes in z axixs from 0 to different heights?
  1 Kommentar
KSSV
KSSV am 23 Okt. 2018
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.

Melden Sie sich an, um zu kommentieren.


muhammad ahmad
muhammad ahmad am 23 Okt. 2018
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

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by