Effacer les filtres
Effacer les filtres

How can i generate random distributed bar objects

1 vue (au cours des 30 derniers jours)
muhammad ahmad
muhammad ahmad le 23 Oct 2018
I need to generate some random bar objects to test my collision avoidance algorithm hoe can I do that?

Réponses (3)

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

Connectez-vous pour commenter.


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

Connectez-vous pour commenter.


muhammad ahmad
muhammad ahmad le 23 Oct 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

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by