필터 지우기
필터 지우기

Generating randomly distributed cylindrical fibers in 3D

조회 수: 3 (최근 30일)
Abdolrasol Rahimi
Abdolrasol Rahimi 2017년 11월 7일
댓글: Walter Roberson 2021년 8월 30일
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
  댓글 수: 4
Walter Roberson
Walter Roberson 2017년 11월 27일
My browser is saying those .jpg contain errors :(
Abdolrasol Rahimi
Abdolrasol Rahimi 2017년 12월 26일
Hi Walter,
I am sorry I thought that I posted the new version of images, but it seems not. Sorry for late response.
I have attached the new version of images. Please let me know if it works for you.

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

채택된 답변

KSSV
KSSV 2017년 12월 27일
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);
  댓글 수: 1
Abdolrasol Rahimi
Abdolrasol Rahimi 2018년 1월 2일
Thank you for the answer. The code is written nicely. I tried to modify the code to have a solid cylinder instead of being hollow, but I was not successful. How can I change it to have a solid cylinder?

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

추가 답변 (1개)

Gabriel Gaal
Gabriel Gaal 2018년 9월 23일
Hi KSSV,
I am trying to use your code, and despite the fact it generates a hollow cylinder, it does not rotate under a arbitrary angle. This code only works for 90, 180, 270 and 360. I am trying to fix it but I am new at MatLab and I having a hard time to doing it. Can you spare a few more thoughts on it?
  댓글 수: 2
amira soliman
amira soliman 2021년 8월 30일
can you please help me to do that if you have a solution because i am trying to have a code to draw randomly oriented fiber in a box
Walter Roberson
Walter Roberson 2021년 8월 30일
Create a cylinder in fixed coordinates, and then apply a general rotation matrix to the coordinates
RA = rand(1,3) * 2*pi;
M = makehgtform('xrotate', RA(1), 'yrotate', RA(2), 'zrotate', RA(3));
XYZ0 = [X1(:), Y1(:), Z1(:), zeros(numel(X1),1)];
RXYZ0 = XYZ0 * M; %matrix multiplication
X1R = RXYZ0(:,1);
Y1R = RXYZ0(:,2);
Z1R = RXYZ0(:,3);

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by