Volume defined by vertices to stl file to mesh
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Thales
am 4 Mär. 2019
Beantwortet: Precise Simulation
am 8 Mär. 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)
stlwrite(TR,'teste.stl') % does not work
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?
0 Kommentare
Akzeptierte Antwort
Precise Simulation
am 8 Mär. 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.
0 Kommentare
Weitere Antworten (1)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!