我是 Matlab 编程的新手。我有两个使用 EIDORS 和 Netgen 由四面体网格创建的模型。然后我需要使用 Matlab 根据四面体元素之间的交集创建一个地图。因此,为了找到交叉点,我尝试使用点测试方法。请参考链接。 http://steve.hollasch.net/cgindex/geometry/ptintet.html
让我们假设model1和model2。
首先,我从模型和创建的矩阵中提取顶点。
然后,我使用点测试方法来计算模型之间的交集。
对于模型 1,我有 3000++ 四面体元素,而模型 2 我有 8000++ 四面体元素。
为了计算交集,我一个接一个地循环确定两个模型之间的哪些元素有交集,然后我通过将model2的元素编号索引到model1的元素编号来创建一个矩阵。
但是,少数元素似乎为零,这是不可能的,因为模型 1 中的所有元素都应该至少与模型 2 中的一些元素相交。
因此,最后我希望得到一个矩阵,包括(模型1的元素数x模型2的元素数,它与模型1中的相应元素相交)。可以帮我解决这个问题吗?请参考我的代码。
function [elemno,deter0,deter1,deter2,deter3,deter4] = checkp(filename1,filename2);
%/* to check whether the vertices of a layered model''s element are inside the
% tetrahedron of the generic model
%after the model is created using netgen and eidors, there will be a struct type
%named model_parameters.
%model_parameters.vtx refers to the vertices which consists of (nodes x vertices %(x,y,z))
%model_parameters.simp refers to the elements which consists (numberofelements x nodes) nodes are linked to the vertices.*/
filename1 = [filename1 '.mat'];
filename2 =[filename2 '.mat'];
first = load(filename1);
second =load(filename2);
vtx = first.model_parameters.vtx;
simp = first.model_parameters.simp;
[simpr,simpc] = size(simp);
vtx2 = second.model_parameters.vtx;
simp2= second.model_parameters.simp;
[simpr2,simpc2] = size(simp2);
%//extracting the vertices of the elements from the simplices(element)
for loop1 = 1 : simpr
elemx(loop1,1) = vtx(simp(loop1,1),1);
elemx(loop1,2) = vtx(simp(loop1,2),1);
elemx(loop1,3) = vtx(simp(loop1,3),1);
elemx(loop1,4) = vtx(simp(loop1,4),1);
elemy(loop1,1) = vtx(simp(loop1,1),2);
elemy(loop1,2) = vtx(simp(loop1,2),2);
elemy(loop1,3) = vtx(simp(loop1,3),2);
elemy(loop1,4) = vtx(simp(loop1,4),2);
elemz(loop1,1) = vtx(simp(loop1,1),3);
elemz(loop1,2) = vtx(simp(loop1,2),3);
elemz(loop1,3) = vtx(simp(loop1,3),3);
elemz(loop1,4) = vtx(simp(loop1,4),3);
end
for loop2 = 1:simpr2
elemx2(loop2,1) = vtx2(simp2(loop2,1),1);
elemx2(loop2,2) = vtx2(simp2(loop2,2),1);
elemx2(loop2,3) = vtx2(simp2(loop2,3),1);
elemx2(loop2,4) = vtx2(simp2(loop2,4),1);
elemy2(loop2,1) = vtx2(simp2(loop2,1),2);
elemy2(loop2,2) = vtx2(simp2(loop2,2),2);
elemy2(loop2,3) = vtx2(simp2(loop2,3),2);
elemy2(loop2,4) = vtx2(simp2(loop2,4),2);
elemz2(loop2,1) = vtx2(simp2(loop2,1),3);
elemz2(loop2,2) = vtx2(simp2(loop2,2),3);
elemz2(loop2,3) = vtx2(simp2(loop2,3),3);
elemz2(loop2,4) = vtx2(simp2(loop2,4),3);
end
%//point test calculation
r =[1;1;1;1];
for a = 1:simpr
m=1;
for b=1:simpr2
for n = 1:4
p = [elemx2(b,n),elemy2(b,n),elemz2(b,n)];
n1=[elemx(a,1),elemy(a,1),elemz(a,1)];
n2=[elemx(a,2),elemy(a,2),elemz(a,2)];
n3=[elemx(a,3),elemy(a,3),elemz(a,3)];
n4=[elemx(a,4),elemy(a,4),elemz(a,4)];
d0 =[n1;n2;n3;n4];
d0 =[d0 r];
d1 =[p;n2;n3;n4];
d1 =[d1 r];
d2 =[n1;p;n3;n4];
d2 =[d2 r];
d3 =[n1;n2;p;n4];
d3 =[d3 r];
d4 =[n1;n2;n3;p];
d4 =[d4 r];
deter0 = sign(det(d0));
deter1 = sign(det(d1));
deter2 = sign(det(d2));
deter3 = sign(det(d3));
deter4 = sign(det(d4));
if isequal(deter0,deter1,deter2,deter3,deter4)
elemno(a,m) = b;
m=m+1;
break;
else
continue;
end
end
end
end