I would like to extract 2D mesh of outer surface of 3D meshed object.
Let's say I have 3D mesh data from here and I import the data into Mathematica.
Needs["NDSolve`FEM`"];
SetDirectory[NotebookDirectory[]];
nodes3Dmesh = Import["nodes_3D_mesh.txt", "Table"];
conn3Dmesh = Import["connection_3D_mesh.txt", "Table"] + 1;
mesh3D = ToElementMesh["Coordinates" -> nodes3Dmesh, "MeshElements" ->
{HexahedronElement[conn3Dmesh]}];(*3D hex mesh*)
Graphics3D[{ElementMeshToGraphicsComplex[mesh3D]}, Axes -> True,
AxesLabel -> {x, y, z}]
Now, I want to extract 2D mesh of surface lying in the x-z plane at y = 0 (this reddish surface in the above picture). My approach to this problem was:
PosNodesY0 = Flatten[Position[nodes3Dmesh, _?(#[[2]] == 0. &)]];(*positions of nodes which
have y coordinate equal to zero*)
conn2Dmesh = Select[Map[Select[#, MemberQ[PosNodesY0, #] &] &, conn3Dmesh],
UnsameQ[#, {}] &];(*computed connections for the 2D mesh*)
mesh2D = ToElementMesh["Coordinates" -> Drop[nodes3Dmesh, None, {2}],
"MeshElements" -> {QuadElement[conn2Dmesh]}];(*resulting 2D quad mesh*)
mesh2D["Wireframe"]
Questions:
- My approach of extracting 2D mesh takes a long time for large 3D meshed object. Specifically the
conn2Dmesh
implementation. It is possible to make it faster? - My approach does not work for surface with more complicated geometry (e.g. white surface in the first picture). Would it be possible to generalize this for any outer surface of 3D object?
I would appreciate any help.