Volume defined by vertices to stl file to mesh

4 visualizaciones (últimos 30 días)
Thales
Thales el 4 de Mzo. de 2019
Respondida: Precise Simulation el 8 de Mzo. de 2019
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?

Respuesta aceptada

Precise Simulation
Precise Simulation el 8 de Mzo. de 2019
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.

Más respuestas (1)

KSSV
KSSV el 4 de Mzo. de 2019
t = DT.ConnectivityList ; % connectivity
p = DT.Points ; % points
  3 comentarios
KSSV
KSSV el 4 de Mzo. de 2019
Show us the whole code you tried and specify your error.
Thales
Thales el 4 de Mzo. de 2019
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.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by