We have tetrahedra mesh we went to extract a sphere from this mesh and adabting the mesh

We do this code, but we found a problem in the output tri
fid = fopen('nodes10.dat');
data = fscanf(fid, '%g %g %g', [3, Inf]);
A = data';
fclose(fid);
A;
n=size(A);
kk=n(1);
R=1.5;
MM=zeros(kk,1);
for k=1:kk
MM(k)=0;
for i=1:3
MM(k)= MM(k)+ A(k,i)*A(k,i);
end
MM(k)=sqrt(MM(k));
end
M = A(MM >R,:);
[x1,y1,z1] = sphere(1);
Psphere = [R*x1(:) R*y1(:) R*z1(:)];
Psphere = unique(Psphere,'rows');
P = [M;Psphere];
plot3(P(:,1),P(:,2),P(:,3),'.')
shp= alphaShape(P(:,1),P(:,2),P(:,3),1);
plot(shp)
shp.Alpha = 2;
[tri,loc] = alphaTriangulation(shp);
fid = fopen('nodess.dat','w');
fprintf(fid,'%i\t %i\t %i\n',loc);
fclose(fid);
fid = fopen('tetreades.dat','w');
fprintf(fid,'%i\t %i\t %i\t %i\n',tri);
fclose(fid);
numtetrahedra = size(tri,1);
numnodes = size(loc);
% model = createpde;
% [gCube,mshC]=geometryFromMesh(model,loc',tri');
% %save ('nodesn.txt', 'tri')
% tri
% loc;
axis equal

3 个评论

And the problem was (based on the last two times you posted this question)...
"the error is in the out put tri, it is not a tetrahedra"
Anyway, I've tried running your code. It has many errors in it, so I am not at all sure what you expect it to do as a result.

We want to create a tetrahedral mesh for a solid tetrahedron with a hollow volume cavity in the center when we run the code we get the following problem: in the output we get incorrect tetrahedra (one tetrahedron have two vertices or more are the same )

请先登录,再进行评论。

回答(2 个)

I had to fixthe filename. You attached file nodes10.txt, but your code calls nodes10.dat. After I fixed that, the script ran without error and it generates a 3D plot of a tetrahedron that looks like it is made of many small tetrahedra. See screenshot.
What else do you want?

7 个评论

I interpret the remarks as indicating that the original poster wants a tetrahedral output rather than a tri output.
@Maroua Guenaoua, you can replace
for k=1:kk
MM(k)=0;
for i=1:3
MM(k)= MM(k)+ A(k,i)*A(k,i);
end
MM(k)=sqrt(MM(k));
end
with
for k=1:kk
MM(k)=norm(A(k,:));
end
@Maroua Guenaoua, if you use the "hand" tool to drag the tetrahedron within the 3D plot, after the script finishes, you will see that it is composed of an outer shell of triangles that form a tetrahedron, and an inner set of triangles that form a rather lumpy sphere. It's hard to appreciate from a static screenshot, but if you do it dynamically, you will see what I mean. Screenshot below.
Yes, that's what I wanted. A 3D plot of a tetrahedron with a cavity sphere, it is made of many small tetrahedra.The error in tri output not a tetrahedras . Look at the picture below
I think the problem is in sphere(n), i do not know how to choose n, can you help me please?
I am sorry to say that I do not understand exactly what the problem is. You said in your comment "look at the picture below", and you provided a screenshot. I cannot tell from that screenshot what the problem is.
Is @Walter Roberson correct when he says "I interpret the remarks as indicating that the original poster wants a tetrahedral output rather than a tri output."? The commented-out lines of your code indicate that you plan to solve a partial differential equation (PDE) model. Are you solving a PDE in a covolume or on the surface (or surfaces)? Are you trying to create a tetrahedral mesh for a solid tetrahedron with a hollow sherical cavity in
the center?
You also said "I think the problem is in sphere(n), i do not know how to choose n, can you help me please?" sphere(n) generates a sphere compsosed of n-by-n faces, where each face is a quadrilateral. The faces at the north pole and south pole look like triangles, because one side of the quadrilateral has length zero. The code blow demonstrates spheres with n=3,4,6,8. The colors are based on the approximate z-value of each face.
subplot(221);sphere(3); axis equal
subplot(222);sphere(4); axis equal
subplot(223);sphere(6); axis equal
subplot(224);sphere(8); axis equal
When I change sphere(1) to sphere(8) in the script, and then rotate and drag the object to see inside, I get the results shown below:
When I use sphere(40) I get the result below:

We want to create a tetrahedral mesh for a solid tetrahedron with a hollow volume cavity in the center when we run the code we get the following problem: in the output we get incorrect tetrahedra (one tetrahedron have two vertices or more are the same )

请先登录,再进行评论。

[Edit: Upload modified version of script - see comment below.]
A modified version of your script is attached. This version generates a triangulation that works with geometryFromMesh(), which means you can use the triangulation for a PDE model. The comments in the script explain the changes I made.
I have also written and uploaded a function to diagnose problems with 2D and 3D triangulations. See Analyze triangulation at the File Exchange.

4 个评论

@Walter Roberson, thank you for bringing it to my attention that the last line of shapeEwr3.m (posted above) contain an error which I hadn't noticed. The line
[tri,loc] = geometryFromMesh(model,loc',tri');
should be
[G,mesh] = geometryFromMesh(model,loc',tri');
With this change, it is evident that script shapeEwr3.m does produce a tetrahedral mesh defined by tri and loc: size(tri)=7551x4; size(loc)=1728x3, indicating a mesh with 7551 tetrahedra and 1728 nodes. I will edit the script attached above to correct this.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by