How can I generate a gaussian distribution of spheres in a cylinder? Spheres doesn't have to overlap. Thanks

4 views (last 30 days)
%check for overlapping
k=1; %start overlap check from the beginning
while k<=i
%take coordinates of k-th sphere
Xk=x1(1,k);
Yk=y1(1,k);
Zk=z1(1,k);
Rk=r(1,k);
%distance between i-th and k-th sphere centers
d(k) =sqrt((X-Xk)^2+(Y-Yk)^2+(Z-Zk)^2);
%sum of i-th and k-th sphere radii
rr(k)=Rk+R;
if d(k) == 0 % exclude itself
break;
elseif d(k) < rr(k) %overlap condition
%generate new coordinate for the i-th sphere
x1(1,i)=x_lo+(x_hi-x_lo)*rand;
y1(1,i)=y_lo+(y_hi-y_lo)*rand;
z1(1,i)=z_lo+(z_hi-z_lo)*rand;
r(i)= random('exp',0.8);
X=x1(1,i);
Y=y1(1,i);
Z=z1(1,i);
R=r(1,i);
k=1; %reset overlap check to the beginning
continue;
else
k=k+1; %continue overlap check for next k-th sphere
continue;
end
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!