I want to create a hexagonal lattice using VoronoiMesh
. One can achieve that with the following code, where L=5
,
pts = Flatten[
Table[{3/2 i, Sqrt[3] j + Mod[i, 2] Sqrt[3]/2}, {i, L}, {j, L}], 1];
mesh = VoronoiMesh[pts]
Changing the code slightly, I can delete the overly sized cells in the following manner
pts = Flatten[
Table[{3/2 i, Sqrt[3] j + Mod[i, 2] Sqrt[3]/2}, {i, L + 2}, {j,
L + 2}], 1];
mesh = VoronoiMesh[pts];
MeshRegion[MeshCoordinates[mesh],
With[{a = PropertyValue[{mesh, 2}, MeshCellMeasure]},
With[{m = 3}, Pick[MeshCells[mesh, 2], UnitStep[a - m], 0]]]]
to get
Now, I want to add a bit of "realism" to the mesh, by including a noise term in each coordinate of the cell centroids.
rt = 0.5;
pts = Flatten[
Table[{3/2 i + RandomReal[rt],
Sqrt[3] j + Mod[i, 2] Sqrt[3]/2 + RandomReal[rt]}, {i,
L + 2}, {j, L + 2}], 1];
mesh = VoronoiMesh[pts];
MeshRegion[MeshCoordinates[mesh],
With[{a = PropertyValue[{mesh, 2}, MeshCellMeasure]},
With[{m = 3}, Pick[MeshCells[mesh, 2], UnitStep[a - m], 0]]]]
As one can see, the MeshCellMeasure
threshold fails in this case, and I get either holes in the mesh or those "pointy" cells that I have previously excluded. How do I solve this?
I thought about tracking the specific boundary cells and delete them from the Voronoi mesh. Is this viable? How could I do that?
RandomPoint
), and carry out enough rounds of Lloyd relaxation on the resulting mesh to get it "regular enough". Should you go this route, you can find excellent code ready to go in Lloyd relaxation onVoronoiMesh
. You should then be able to use your own code to remove the "borders". $\endgroup$