Borrar filtros
Borrar filtros

Intersection of Fibers...

1 visualización (últimos 30 días)
Sushant
Sushant el 13 de Jul. de 2022
Comentada: Jan el 13 de Jul. de 2022
I have written a code regarding checking for intersection of fibers within the fibers...but there is some errors in it...I am unable to fix it. Kindly help
function FibList=Generatefibers_trial(x,y,z,L,N)
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); %angle
gamma=2*pi*rand(1); %angle
phi=2*pi*rand(1); %angle
Dr=[cos(gamma)*cos(phi)-cos(theta)*sin(gamma)*sin(phi) sin(gamma)*cos(phi)+cos(theta)*cos(gamma)*sin(phi) sin(theta)*sin(phi) ...
; -cos(gamma)*sin(phi)-cos(theta)*sin(gamma)*cos(phi) -sin(gamma)*sin(phi)+cos(theta)*cos(gamma)*cos(phi) sin(theta)*cos(phi) ...
; sin(theta)*sin(gamma) -sin(theta)*cos(gamma) cos(theta) ];
c2=[x1 y1 z1]'+Dr*[L 0 0]';
x2=c2(1);
y2=c2(2);
z2=c2(3);
if x2<=x(2) && x2>=x(1) && y2<=y(2) && y2>=y(1) && z2<=z(2) && z2>=z(1)
break;
end
end
% Coordinates
Fiber(i,1)=x1;
Fiber(i,2)=y1;
Fiber(i,3)=z1;
Fiber(i,4)=x2;
Fiber(i,5)=y2;
Fiber(i,6)=z2;
% Matrix representation of the coordinates generated.
if i==1
FibList=[Fiber(i,1) Fiber(i,2) Fiber(i,3) Fiber(i,4) Fiber(i,5) Fiber(i,6)];
else
NewFib=[Fiber(i,1) Fiber(i,2) Fiber(i,3) Fiber(i,4) Fiber(i,5) Fiber(i,6)];
j=1;
count=0;
while j<i
syms s t
eqn1=s*(FibList(j,4)-FibList(j,1))-t*(NewFib(1,4)-NewFib(1,1)) == NewFib(1,1)-FibList(j,1); % I am getting error in this line.
eqn2=s*(FibList(j,5)-FibList(j,2))-t*(NewFib(1,5)-NewFib(1,2)) == NewFib(1,2)-FibList(j,2);
[A, B] = equationsToMatrix([eqn1, eqn2],[s,t]);
X=linsolve(A,B);
s=vpa(X(1,1));
t=vpa(X(2,1));
%Criteria for checking intersection of 2 line segments in 3D.
if (s>=0 && s<=1)&&(t>=0 && t<=1)&&((s*(FibList(j,6)-FibList(j,3))-t*(NewFib(1,6)-NewFib(1,3))== NewFib(1,3)-FibList(j,3)))
count=count+1;
end
j = j+1;
end
%fprintf('the value of s is %f\n the value of t is %f ',X)
if count==i-1
FibList = [FibList; NewFib];
else
FibList = [FibList];
i = i-1; % this will repeat the loop for the same i value, if the intersection criteria...
%is not fulfilled.
end
end
end
end
Error messgae:
Index exceeds matrix dimensions.
Error in Generatefibers_trial (line 39)
eqn1=s*(FibList(j,4)-FibList(j,1))-t*(NewFib(1,4)-NewFib(1,1)) == NewFib(1,1)-FibList(j,1);
  3 comentarios
Sushant
Sushant el 13 de Jul. de 2022
Kindly help me in fixing the error.
Jan
Jan el 13 de Jul. de 2022
Simplify
FibList=[Fiber(i,1) Fiber(i,2) Fiber(i,3) Fiber(i,4) Fiber(i,5) Fiber(i,6)];
to
FibList = Fiber(i, 1:6);
You can use the debugger to stop the execution, when the error occurs. Type in the command window:
dbstop if error
Now run the code again and check the values of the indices, when the error occurs.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by