Random 3D Array of Cylinders with Random Rotation and Fixed Length
9 ビュー (過去 30 日間)
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));
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;
p1 = [x y z];
p2 = [-x y -z];
surf(X, Y, Z)
回答 (1 件)
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.