Generate random short fiber in matlab?

6 vues (au cours des 30 derniers jours)
RAJESH le 11 Jan 2023
Commenté : Rik le 16 Jan 2023
Kindly look into the below code, i am not able to run it, if there is any issue.
function Fiber=Generate_Fiber(x,y,z,L,N)
%input
%x=[x1 x2]: x boundaries of the box
%y=[y1 y2]: y boundaries of the box
%z=[z1 z2]: z boundaries of the box
%L: Length of fibers
%N: Number of fibers
%output
%Fiber: (N,6) matrix of fiber coordinates with (:,1), (:,2) and (:,3) are x,y, and z coordinates of one end
%and (:,4),(:,5) and (:,6) are x,y, and z coordinates of the other end.
for i=1:1:N
while 1
x1=min(x)+(max(x)-min(x))*rand(1);
y1=min(y)+(max(y)-min(y))*rand(1);
z1=min(z)+(max(z)-min(z))*rand(1);
theta=2*pi*rand(1);
v=2*rand(1)-1;
x2=x1+L*sqrt(1-v^2)*cos(theta);
y2=y1+L*sqrt(1-v^2)*sin(theta);
z2=z1+L*v;
if x2<=x(2) && x2>=x(1) && y2<=y(2) && y2>=y(1) && z2<=z(2) && z2>=z(1)
break;
end
end
Fiber(i,1)=x1;
Fiber(i,2)=y1;
Fiber(i,3)=z1;
Fiber(i,4)=x2;
Fiber(i,5)=y2;
Fiber(i,6)=z2;
end
0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Réponse acceptée

Dongyue le 13 Jan 2023
result = Generate_Fiber([0,1],[0,1],[0,1],0.5,2)
result = 2×6
0.2385 0.2689 0.0838 0.1044 0.6092 0.4247 0.3414 0.2479 0.6434 0.6763 0.0375 0.9493
function Fiber=Generate_Fiber(x,y,z,L,N)
%input
%x=[x1 x2]: x boundaries of the box
%y=[y1 y2]: y boundaries of the box
%z=[z1 z2]: z boundaries of the box
%L: Length of fibers
%N: Number of fibers
%output
%Fiber: (N,6) matrix of fiber coordinates with (:,1), (:,2) and (:,3) are x,y, and z coordinates of one end
%and (:,4),(:,5) and (:,6) are x,y, and z coordinates of the other end.
Fiber = zeros(N,6);
for i=1:1:N
while 1
x1=min(x)+(max(x)-min(x))*rand(1);
y1=min(y)+(max(y)-min(y))*rand(1);
z1=min(z)+(max(z)-min(z))*rand(1);
theta=2*pi*rand(1);
v=2*rand(1)-1;
x2=x1+L*sqrt(1-v^2)*cos(theta);
y2=y1+L*sqrt(1-v^2)*sin(theta);
z2=z1+L*v;
if x2<=x(2) && x2>=x(1) && y2<=y(2) && y2>=y(1) && z2<=z(2) && z2>=z(1)
break;
end
end
Fiber(i,1)=x1;
Fiber(i,2)=y1;
Fiber(i,3)=z1;
Fiber(i,4)=x2;
Fiber(i,5)=y2;
Fiber(i,6)=z2;
end
end
5 commentairesAfficher 3 commentaires plus anciensMasquer 3 commentaires plus anciens
RAJESH le 16 Jan 2023
Could you please provide me, some example code or tutorial for random fiber poistioning(RVE) and Generate random fiber?
Rik le 16 Jan 2023
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).

Connectez-vous pour commenter.

Catégories

En savoir plus sur Fluid Dynamics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by