Volume defined by vertices to stl file to mesh

조회 수: 14 (최근 30일)
Thales
Thales 2019년 3월 4일
답변: Precise Simulation 2019년 3월 8일
Hi,
I have the following points defining a hexahedra in space.
x = [0 0 0 0 0.1 0.1 0.1 0.1]';
y = [0 0.1 0 0.1 0 0.1 0 0.1]';
z = [0 0 100e-6 100e-6 0 0 50e-6 50e-6]';
figure
plot3(x,y,z,'.')
DT = delaunayTriangulation(x,y,z)
C = convexHull(DT)
trisurf(C,x,y,z)
I would like to create an stl triangular mesh file to use it with the FEATool toolbox.
My MATLAB version is R2017b, so I don't have acces to the native function introduced in R2018b.
stlwrite(TR,'teste.stl') % does not work
There is a stlwrite function in the File Exchange, but it is not working properly.
How do I create the FACES and VERTICES to use the File Exchange function properly from the points I defined or is there other way to write this stl file?
The FEATool allows us to create and refine the mesh, so I would need only the faces of the hexahedra, not to pass the actual discretized mesh to the toolbox.
Any hints on how to create the FACES and VERTICES from the points defining the hexahedra and how to create the stl file?

채택된 답변

Precise Simulation
Precise Simulation 2019년 3월 8일
As this is a simple case, you can just create a FEATool Multiphysics toolbox compatible STL file manually, for example with the following code
x = [0 0 0 0 0.1 0.1 0.1 0.1]';
y = [0 0.1 0 0.1 0 0.1 0 0.1]';
z = [0 0 100e-6 100e-6 0 0 50e-6 50e-6]';
DT = delaunayTriangulation(x,y,z);
C = convexHull(DT);
fid = fopen( 'featool.stl', 'w' );
s_fmt = [' facet normal %g %g %g\n', ...
' outer loop\n', ...
' vertex %g %g %g\n', ...
' vertex %g %g %g\n', ...
' vertex %g %g %g\n', ...
' endloop\n', ...
' endfacet\n'];
fprintf( fid, 'solid\n' );
for i=1:size(C,1)
p1 = DT.Points(C(i,1),:);
p2 = DT.Points(C(i,2),:);
p3 = DT.Points(C(i,3),:);
n = cross( p1-p2, p1-p3 );
n = n/norm(n);
fprintf( fid, s_fmt, n, p1, p2, p3 );
end
fprintf( fid, 'endsolid' );
fclose( fid );
However, as this is a very simple geometry and one with very large aspect ratio, it is faster and probably also better to just create the mesh manually directly. For example using the built-in blockgrid and gridrefine commands, one gets
grid = blockgrid( 1, 1, 1, [0 0.1;0 0.1;0 100e-6] );
grid.p(3,[6,8]) = 50e-6;
for i=1:3
grid = gridrefine( grid );
end
plotgrid( grid )
axis normal
Please be aware that the aspect ratio of this geometry is 2000 which is very high, to get good results from your simulations you had better scale the equations in the z-direction correspondingly.

추가 답변 (1개)

KSSV
KSSV 2019년 3월 4일
t = DT.ConnectivityList ; % connectivity
p = DT.Points ; % points
  댓글 수: 3
KSSV
KSSV 2019년 3월 4일
Show us the whole code you tried and specify your error.
Thales
Thales 2019년 3월 4일
That is the whole code. I thought it would be simple to do it.
x = [0 0 0 0 0.1 0.1 0.1 0.1]';
y = [0 0.1 0 0.1 0 0.1 0 0.1]';
z = [0 0 100e-6 100e-6 0 0 50e-6 50e-6]';
figure
plot3(x,y,z,'.')
DT = delaunayTriangulation(x,y,z)
C = convexHull(DT)
trisurf(C,x,y,z) % creates the figure shown. This looks correctly,
% I have a triangulation of each face
Capturar.PNG
When trying to write it to a stl
stlwrite('test.stl',DT.ConnectivityList,DT.Points)
The stlwrite function returns the following error message:
Error using stlwrite1>parseInputs (line 201)
The FACES input array should hold triangular faces (N x 3), but was detected as N x 4.
The STL format is for triangulated surfaces (i.e., surfaces made from 3-sided triangles).
The Geom3d package (https://www.mathworks.com/matlabcentral/fileexchange/24484-geom3d) contains
a "triangulateFaces" function which can be used convert your faces into triangles.
Error in stlwrite (line 76)
[faces, vertices, options] = parseInputs(varargin{:});
Which makes sense, I need a triangulated face not a tetrahedra. That is the reason to why I use the convexHull function.
stlwrite1('test.stl',C,[x y z])
This returns the following message
Wrote 3 faces
Which is incorrect, since I have now 12 triangulated faces.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 STL (STereoLithography)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by