How can i generate random distributed bar objects

1 次查看(过去 30 天)
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