I think this may work though I'm not sure why. I made it up through trial and error, aiding by #18514. You'll need nextCandidate
and FindFace
from there.
First of all since you haven't provide some example data, let me generate some wireframe:
mesh = MeshRegion[
MeshCoordinates[#],
MeshCells[#, 1]
]& @ VoronoiMesh[RandomReal[{0, 1}, {100, 2}]]
Then,
graph1 = Graph[
MeshCoordinates[mesh],
MeshCells[mesh, 1] /. Line[{start_, end_}] -> {start, end},
VertexCoordinates -> MeshCoordinates[mesh],
GraphLayout -> "PlanarEmbedding"
];
graph2 = Graph[
MeshCells[mesh, 1] /. Line[{start_, end_}] -> start <-> end
];
adj = AdjacencyMatrix[graph2];
graph3 = AdjacencyGraph[adj, GraphLayout -> "PlanarEmbedding"];
faces = FindFace[graph3];
meshpolygons = MeshRegion[
VertexList[graph1][[VertexList[graph2]]],
Polygon /@ Most[SortBy[faces, Length]]
]
Then you can obtain the area of each polygon as follows:
Area /@ (MeshCells[meshpolygons, 2] /. x_Integer :> MeshCoordinates[meshpolygons][[x]])
Let's see if the method works for your specific wireframe.
Some explanation:
Basically your problem is about detecting smallest polygons from connected lines. This requires some clever algorithm. Thankfully we have #18514. We can turn our wireframe into a graph and use the method there.
graph1
is the straightforward conversion. It doesn't have any crossings, but for some reason it doesn't work with FindFace
. (I haven't taken time to study it.) Possibly the function requires its argument's structure to be of certain canonical form, so I convert graph1
to an adjacency matrix first and then obtain graph3
.
graph1
contains the actual positions of the vertices, so we need VertexList[graph1]
in meshpolygons
, but the ordering of the vertices used in faces
is from graph2
, hence VertexList[graph1][[VertexList[graph2]]]
.
faces
also includes the largest, encompassing polygon. I assume that it has the most vertices and remove it with Most
after sorting the list of faces by the number of their vertices.
N
as a variable name, as it's the name of the built-in functionN
. $\endgroup$