So, I can create a circle filled with circles of the same radius that gives this example picture:
with this code:
generateCirclesSameRadius[numCircles_Integer, boundaryRadius_, circleRadius_, maxAttempts_Integer] :=
Module[{circles = {}, attempt = 0, newCircle, canPlace},
While[Length[circles] < numCircles && attempt < maxAttempts,
newCircle = RandomPoint[Disk[{0, 0}, boundaryRadius - circleRadius]];
canPlace = True;
Do[
If[Norm[newCircle - circle] < 2 circleRadius, canPlace = False; Break[];],
{circle, circles[[All, 2]]}
];
If[canPlace, AppendTo[circles, {circleRadius, newCircle}]];
attempt++;
];
circles
]
drawCircles[circles_] :=
Graphics[{EdgeForm[Black], FaceForm[None], Circle[{0, 0}, boundaryRadius],
FaceForm[RandomColor[]], Circle[#[[2]], #[[1]]] & /@ circles}]
fixedRadius = 0.1; (* Adjust based on the boundary radius and desired number of circles )
boundaryRadius = 2;
numCircles = 10; ( Adjust based on available space and circle radius *)
maxAttempts = 100;
circles = generateCirclesSameRadius[numCircles, boundaryRadius, fixedRadius, maxAttempts];
drawCircles[circles]
And I can check overlaps of an ellipse with this code:
OverlapQ[ellipse1_List, ellipse2_List] :=
Module[
{a, b, \[Alpha], \[Beta], c, d, \[Delta], \[Gamma], ell1, ell2, int, realIntersectionExists},
(* Extract ellipse parameters from the lists *)
{a, b, [Alpha], [Beta]} = ellipse1;
{c, d, [Delta], [Gamma]} = ellipse2;
(* Define the parametric equations for the ellipses *)
ell1[t_] := {a Cos[t] + [Alpha], b Sin[t] + [Beta]};
ell2[t_] := {c Cos[t] + [Delta], d Sin[t] + [Gamma]};
(* Solve for intersection points, focusing on real solutions *)
int = Quiet[Solve[ell1[t] == ell2[s], {s, t}]];
(* Determine if there is at least one real intersection point *)
realIntersectionExists = Length[Select[int, FreeQ[#, Complex] &]] > 0;
(* Return True if there is at least one actual intersection, else False *)
realIntersectionExists
]
Which can be called with:
ellipse1 = {1, 0.5, 0, 0};
ellipse2 = {0.8, 0.9, 1, 1};
OverlapQ[ellipse1, ellipse2]
(gives True)
But I feel like there should be a more efficient way than to check the overlap of each this way or at least a more compact, readable method to do this. This is a very general problem that I think many people would use if solved.












LibraryFunctionthat uses it correctly, if you like. – Henrik Schumacher Feb 12 '24 at 15:38