A Smooth and Round Voronoi Mesh
1 + 4
We can discretize the rounded Polygon
objects and then add the negative of the mesh through Prolog
.
rm = DiscretizeGraphics[roundedPolygon[#, 0.3] & /@ MeshPrimitives[mesh, 2]]
Now there's some floating point differences in the results from roundedPolygon
that seem to effect subsequent Boolean operations. We can fix this crudely merging nearby points.
coordsnew = Mean /@ Nearest[MeshCoordinates[rm], MeshCoordinates[rm], {All, 10^-12.}];
rm = MeshRegion[coordsnew, MeshCells[rm, 2]];
Now find the difference:
diff = BoundaryMesh @ RegionDifference[
Cuboid @@ Transpose[CoordinateBounds[MeshCoordinates[rm], Scaled[.05]]], rm]
And assemble:
joints = With[{comps = ConnectedMeshComponents[diff]},
If[Length[comps] == 1,
{},
Show[
BoundaryMeshRegion[
RegionUnion[Rest[SortBy[comps, RegionBounds]]],
MeshCellStyle -> {1 -> None, 2 -> GrayLevel[.3]}]
][[1]]
]
];
MeshRegion[
rm,
MeshCellStyle -> {1 -> {Thick, GrayLevel[.3]}, 2 -> LightBlue},
Prolog -> joints
]
3
It seems roundedPolygon
is effected by an unnecessary run of consecutive duplicate points. We can fix this by deleting them.
roundedPolygon[p:Polygon[_?MatrixQ], zero_?PossibleZeroQ, ___] := p
roundedPolygon[Polygon[opts_?MatrixQ], r_?Positive, n : (_Integer?Positive) : 12] :=
With[{pts = Split[opts][[All, 1]]},
Polygon[Flatten[arcgen[#, r, n] & /@
Partition[
If[TrueQ[First[pts] == Last[pts]], Most, Identity][pts],
3, 1, {2, -2}
], 1]]
]
Edit
We can use MeshCellShapeFunction
to preserve the data in the original mesh while having custom rounded cells:
meshsty = MeshRegion[
mesh,
MeshCellShapeFunction -> {2 -> (roundedPolygon[Polygon[#], 0.3]&)},
MeshCellStyle -> {1 -> {Thick, GrayLevel[.3]}, 2 -> LightBlue},
Epilog -> joints
]
Notice that this only the visualization is affected and not the underlying data:
RegionEqual[mesh, meshsty]
True
Whereas the original solution does change the underlying data:
RegionEqual[mesh, rm]
False
- fill the gaps between cells
Graphics[{PointSize[1 / L2 / 3], Red, MeshPrimitives[mesh, {0, "Interior"}],
{Directive[LightBlue, EdgeForm[Gray], EdgeThickness -> .001],
roundedPolygon[#, 0.3]} & /@ MeshPrimitives[mesh, 2]}]