필터 지우기
필터 지우기

Random 3D Array of Cylinders with Random Rotation and Fixed Length

조회 수: 17 (최근 30일)
Sam Bottum
Sam Bottum 2022년 11월 29일
댓글: Sam Bottum 2022년 11월 29일
Hi all,
I am trying to generate a function that creates a 3D array of some number of cylinders of fixed length and radius within a given volume. I want them to be randomly distributed in xyz and have a random rotation, but no overlapping.
I have gotten the rotation part done by randomizing phi and theta in spherical coordinates and then converting to cartesian, but am unsure of where to go from here. Any thoughts would be appreciated!
Note: this currently uses the function "cylinder2p" that someone else has written, which takes an input of the 2 endpoints of a cylinder.
%setting boundaries for orientation
NW_l = 25;
phi_min = 0;
phi_max = 360;
theta_min = 0;
theta_max = 360;
%setting boundaries for max x,y,z position
max_x = 50;
max_y = 50;
max_z = 50;
%setting cylinder2P parameters
facet = 40; %# of facets around cylinder
rad_single = 1; %radius of cylinder/NW
rad_vector = rad_single*(ones(facet,1));
hold on
for n = [1:5]
NW_phi = phi_max+(phi_min-phi_max)*rand(1,1); %random phi
NW_theta = theta_max+(theta_min-theta_max)*rand(1,1); %random theta
[x,y,z]=sph2cart(NW_phi,NW_theta,NW_l); %convert to cartesian coordinates
%quiver3(25-x+150*n,25,25,x,y,z) %plot NW orientation
%quiver3(-x,-y,-z,x,y,z,2,'LineWidth',3,'color','k','ShowArrowHead','off') %plot NW orientation
%r = 0.2;
%[x,y,z] = cylinder(r);
%h = 50;
%z = z*h;
%surf(x,y,z)
p1 = [x y z];
p2 = [-x y -z];
[X,Y,Z]=cylinder2P(rad_vector,facet,p1,p2);
surf(X, Y, Z)
end
%axis equal
hold off
xlabel('x')
ylabel('y')
zlabel('z')
  댓글 수: 2
Bruno Luong
Bruno Luong 2022년 11월 29일
NOTE random uniform phi/theta is NOT random uniform orientation. Therefore your code generates cylinders orienations that has biased.

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

답변 (1개)

John D'Errico
John D'Errico 2022년 11월 29일
THERE IS NO SIMPLE SOLUTION. Accept that. For example, even for as simple a problem as random sphere packing, where you want to assign spheres "randomly" in a domain so there are no overlaps, there is no simpler solution than to generate sets of sphere centers, and then discard those that overlap, or try to move them so there is no overlap.
But worse, you want to do that with a non-simple object like a cylinder, which has far less trivial shape than a sphere. Sorry.
  댓글 수: 3
Bruno Luong
Bruno Luong 2022년 11월 29일
편집: Bruno Luong 2022년 11월 29일
This is non trivial task as John pointed out.
You can use rejection by computing the distance between random cylinders, or repulsive force to push new random cylinder away from existing cylinders. If you need any assistance on computing the distance between cylinders and to known if they intersect this FEX can be useful. It has also function to compute distrance of cylindet to shpere/point/plane.
Sam Bottum
Sam Bottum 2022년 11월 29일
I feel confident that I can work out the rejection process after generating the array but am really having trouble getting the random spacing at all.

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by