$Version
"10.3.0 for Linux x86 (64-bit) (October 9, 2015)"
(I use codes originally created by Andy Ross, ybeltukov and J.M.).
I am wondering if one can find the maximum number of randomly generated circles inside a given ellipse.
Using the function findPoints defined below
findPoints =
Compile[{{n, _Integer}, {low, _Real}, {high, _Real}, {minD, _Real}},
Block[{data = RandomReal[{low, high}, {1, 2}], k = 1, rv, temp},
While[k < n, rv = RandomReal[{low, high}, 2];
temp = Transpose[Transpose[data] - rv];
If[Min[Sqrt[(#.#)] & /@ temp] > minD, data = Join[data, {rv}];
k++;];];
data]];
and taking
npts = 150;(*number of points*)
r = 0.03;(*radius of the circles*)
minD = 2.2 r;(*minimum distance in terms of the radius*)
low = 0; (*unit square*)
high = 1;(*unit square*)
ep = With[{a = 2/5, b = 1/2},
BoundaryDiscretizeRegion@
ParametricRegion[(low + high) {1, 1}/2 +
c ({a Cos[t], b Sin[t]} +
r Normalize[Cross[D[{a Cos[t], b Sin[t]}, t]]]), {{c, 0,
1}, {t, 0, 2 \[Pi]}}]];
SeedRandom[159];
pts = Select[findPoints[npts, low, high, minD], RegionMember[ep, #] &];
g2d = Graphics[{Disk[#, r] & /@ pts, Circle[{1/2, 1/2}, {2/5, 1/2}]},
PlotRange -> All, Frame -> True]
we get
and 72 circles (disks) are lying within the ellipse.
pts // Length
(*72*)
Now I increase progressively the number npts.
npts = 160;
SeedRandom[159];
pts = Select[findPoints[npts, low, high, minD],
RegionMember[ep, #] &] // Length
(*80*)
npts = 170;
SeedRandom[159];
Timing[(pts = Select[findPoints[npts, low, high, minD],
RegionMember[ep, #] &] )// Length]
(*{8.23561, 87}*)
npts = 171;
r = 0.03;
minD = 2.2 r;
low = 0;
high = 1;
SeedRandom[159];
Timing[(pts =
Select[findPoints[npts, low, high, minD],
RegionMember[ep, #] &]) // Length]
(*{12.7237, 87}*)
I guess that we have reach a plateau as it is clear below.
g2d = Graphics[{Disk[#, r] & /@ pts, Circle[{1/2, 1/2}, {2/5, 1/2}]},
PlotRange -> All, Frame -> True]
My question now is how we can use Mathematica in order to extract the maximum number of not intersecting circles withing an ellipse?
Thank you very much.







