Generate random short fiber in matlab?

2 次查看(过去 30 天)
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

采纳的回答

Dongyue
Dongyue 2023-1-13
Please try this
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 个评论
RAJESH
RAJESH 2023-1-16
Could you please provide me, some example code or tutorial for random fiber poistioning(RVE) and Generate random fiber?
Rik
Rik 2023-1-16
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by