MATLAB: Generating randomly distributed cylindrical fibers in 3D

randomrandom number generator

Hello,
I am trying to Generate a 3D structure with randomly distributed cylindrical fibers. I would appreciate any help or any code that help me to have a quick start.
Thanks, Hamed

Best Answer

With the below code..you can draw a cylinder of given radius and height....ans also you can rotate this cylinder to any arbitrary angle.
% Units are considered in MKS system
Radius = 0.1 ; % Radius of the cylindrical shell
theta = 360. ; % Angle of the Cylinder
Height = 20. ; % Height of the Cylinder
%

NH = 20 ; % Number of Elements on the Height
NT = 50 ; % Number of Angular Dicretisation
%
nel = NH*NT ; % Total Number of Elements in the Mesh
nnel = 4 ; % Number of nodes per Element
% Number of points (nodes) on the Height and Angluar discretization
npH = NH+1 ;
npT = NT+1 ;
nnode = npH*npT ; % Number of nodes
% Discretizing the Height and Angle of the cylinder
nH = linspace(0,Height,npH) ;
nT = linspace(0,theta,npT)*pi/180 ;
[H, T] = meshgrid(nH,nT) ;
% Convert grid to cylindrical coordintes
X = Radius*cos(T);
Y = Radius*sin(T);
Z = H ;
surf(X,Y,Z) ;
% axis equal
% axis([-5 5 -5 5 -10 10])
%%Rotate cylinder
% set up rotation matrix:
theta = 90; % angle in degrees
theta = theta* pi/180;
R = [cos(theta) 0 sin(theta); 0 1 0; -sin(theta) 0 cos(theta)];
% get points at the two rings and rotate them separately:
P = [X(:) Y(:) Z(:)] ;
Q = P*R;
% reassemble the two sets of points into X Y Z format:
X1 = reshape(Q(:,1),npT,npH) ;
Y1 = reshape(Q(:,2),npT,npH) ;
Z1 = reshape(Q(:,3),npT,npH) ;
figure;
surf(X1,Y1,Z1);