How can I add vertices interior to a geometry before meshing?

5 visualizzazioni (ultimi 30 giorni)
I have an STL that I would like to mesh using tetrahedral elements, but I would like to ensure that specific coordinates interior to the STL contain vertices in the final mesh. I have figured out how to specify coordinates on the surface of the STL using addVertex (see below code). Is there a similar way to add vertices on the interior of the STL?
clear; close all; clc;
% Create an STL
Lx = 3; Ly = 1; Lz = 1;
N = 100;
Nx = Lx*N; Ny = Ly*N; Nz = Lz*N;
dx = Lx/Nx; dy = Ly/Ny; dz = Lz/Nz;
[X,Y,Z] = meshgrid(-dx/2:dx:Lx+dx/2,-dy/2:dy:Ly+dy/2,-dz/2:dz:Lz+dz/2);
V = ones(Ny,Nx,Nz);
V = padarray(V,[1,1,1],"both");
[f,v] = isosurface(X,Y,Z,V,0.5);
TR = triangulation(f,v);
stlwrite(TR,'rectblock2.stl');
% Create a geometry from the STL
model = createpde('structural','static-solid');
g=importGeometry(model,'rectblock2.stl');
% Add vertices on surface
addCoord = [0.5,0.5,1;
1,0.5,1;
1.5,0.5,1;
2,0.5,1;
2.5,0.5,1];
% Would like to also add coordinate [1.5,0.5,0.5], but addVertex needs
% coordinate on the surface of the geometry
VertexID = addVertex(g,"Coordinates",addCoord);
% Generate mesh and plot
mesh = generateMesh(model,'GeometricOrder','linear');
pdeplot3D(model,'FaceAlpha',0.3); hold on
plot3(addCoord(:,1),addCoord(:,2),addCoord(:,3),'or','LineWidth',2);

Risposte (1)

Maneet Kaur Bagga
Maneet Kaur Bagga il 29 Mar 2024
Hi,
As per my understanding, you want to include interior points as vertices in the mesh for a geometry defined by STL file.
One of the possible workarounds for this is using "TetGen" which is a software package for generating tetrahedral meshes, which can be controlled through MATLAB to include interior points in the meshing process. You can refer to the bleow attached File Exchange link for the function "read_tetgenmesh" which reads the native "TetGen" mesh files into MATLAB.
The following steps can be followed:
You already have the STL File. Prepare a list of interior points that you wish to include as vertices in the final mesh.
interiorPoints = [1.5, 0.5, 0.5];
Convert your STL File into one of the TetGen Formats. Now you can run TetGen with the following command, "-p" tells TetGen to tetrahedralize a .poly file, Y suppresses boundary facets/segments splitting, and V adds volume constraints which can be used to specify your interior points.
system('tetgen -pYV yourGeometry.poly');
After running TetGen a tetrahedral mesh will be generated that includes the interior points and the output generated can be imported back to MATLAB using the "read_tetgenmesh" function. You can then visualize your mesh in MATLAB to see that the interior points have now been included.
% Example code to plot the mesh - adjust according to your data structure
pdemesh(p, t, []), hold on
plot3(interiorPoints(:,1), interiorPoints(:,2), interiorPoints(:,3), 'r*', 'MarkerSize', 10)
hold off
Please refer to the below File Exchange link for accessing the "read_tetgenmesh" function:
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by