I want to draw the following graph
using VoronoiMesh
. For example, since
L = 3;
pts = Flatten[
Table[{3/2 i, Sqrt[3] j + Mod[i, 2] Sqrt[3]/2}, {i, L + 4}, {j,
L + 4}], 1];
mesh0 = VoronoiMesh[pts];
gr = Graph[mesh0["Edges"],
VertexCoordinates -> MeshCoordinates[mesh0]]
yields
I thought about "trimming" the Voronoi mesh in the following manner (see this question for more info)
mesh1 = MeshRegion[MeshCoordinates[mesh0],
With[{a = PropertyValue[{mesh0, 2}, MeshCellMeasure]},
With[{m = 3}, Pick[MeshCells[mesh0, 2], UnitStep[a - m], 0]]]];
mesh = MeshRegion[MeshCoordinates[mesh1], MeshCells[mesh1, {2, "Interior"}]]
However, when using either mesh["Edges"]
or mesh["Coordinates"]
for this mesh
, I get the following error
Any idea why?
Regarding the mesh coordinates, I can solve it using MeshCoordinates[mesh]
instead. However, I cannot get the connectivity needed to build the graph. Somehow, MeshRegion
used in this way seems to lose (or change) some of its properties. I've also tried, using something like (from this question)
gvoronoi =
AdjacencyGraph[mesh["AdjacencyMatrix"],
VertexCoordinates -> MeshCoordinates[mesh]]
but with no success. Any ideas?
Additionally, if you have any better suggestions regarding building a graph like this, for any L
, please feel free to share!
Graph[UndirectedEdge @@@ MeshCells[mesh, 1][[All, 1]], VertexCoordinates -> MapIndexed[First[#2] -> #1 &, MeshCoordinates[mesh]]]
. $\endgroup$