I was trying to solve this question out of interest and thought perhaps creating a Voronoi mesh, cropping it to a circle, and colouring the mesh cells might work. However, if I ask VoronoiMesh
to create cells for too many points MeshCellCount[mesh, 2]
(or equivalently Length@MeshCells[mesh]
) it returns a number that is smaller than the number of points provided initially.
I've tried using different functions to generate the points around which the cells should be built, used both exact and real numbers, and checked out the documentation for VoronoiMesh
and MeshRegion
, but I'm still not sure what's causing this. Are my points simply too close together for VoronoiMesh
to uniquely determine a cell for some of them?
The simplest code that reproduces this is:
MeshCellCount[
VoronoiMesh[
Flatten[Quiet[Thread[CirclePoints[Range[100], 360]]], 1]
],
2]
which should return 36,000 since it is 100 radial points and 360 azimuthal points, but instead returns 35,985. For this code it seems to start when there's around 32,000 elements. If the radial points inside Range
are set to 87, I get the expected result. If the radial points are set to 88 (with the same 360 azimuthal points) I get an unexpected result. For all smaller numbers it seems to work as expected.
For some reason, if I use the following code to determine the number of cells, this discrepancy shows up at even smaller numbers of cells.
generate[i_] :=
Table[
{r Sin[θ], r Cos[θ]},
{θ, 0, 359 π/180, π/180},
{r, 1/2, (i - 1) + 1/2}
]
66*360 - MeshCellCount[VoronoiMesh[Flatten[generate[66], 1]], 2]
The result of this code is 2 where I would expect it to be zero for all values passed to generate
.
Does anyone know what I'm doing wrong or if there is a workaround? Or am I simply asking too much of VoronoiMesh
?