@kglr beat me to posting and has a much nicer answer, but since I interpreted the question slightly differently, I thought it might be helpful to post my answer too.
(Edit: Updated based on comment by @JackLaVigne to accelerate by getting rid of empty intersections, see module below for timing.)
Since OP says that "some of the circles may overlap", I assumed that $r$ might be much smaller than the PlotRange and that the goal was to find regions with any overlap (between 2 or more circles).
First, we can construct and plot the set of allCircles (using Disks
as opposed to Circles
so that we can use the Area
function later):
m = 125;
r = 100;
pt[i_] := RandomReal[{-4000, 4000}, 2];
allCircles = Table[Disk[pt[i], r], {i, m}];
g10 = Graphics[allCircles, Axes -> True, PlotRange -> {{-5000, 5000}, {-5000, 5000}}]
Then, we can calculate the total area (sum of all circles):
totalArea = Total[Map[Area, allCircles]];
(*3.92699*10^6*)
Next, we can consider the RegionIntersection for all two circle subsets (using @JackLaVigne's suggestion to get rid of empty intersections) and calculate the overlap/total ratio:
circlePairs = Map[RegionIntersection, Subsets[allCircles, {2}]]/.emptyRegion[2]->Nothing;
overlappingArea = Total[Map[Area, circlePairs]]
(*99293.3 for the plotted case above*)
areaRatio = overlappingArea/totalArea
(*0.0252848 for the plotted case above*)
This calculations assumes there they are no overlapping regions between more than two circles. The circlePairs
area would double count such regions, but that could be corrected by considering the overlaps of, for example, circleTriplets
.
EDIT Here is a Module form that runs in 6-10 seconds on my laptop for m=125
and r=100
:
overlapAreaModule[shapes_] :=
Module[{totalArea, shapePairs, overlappingArea, areaRatio},
totalArea = Total[Map[Area, shapes]];
shapePairs =
Map[RegionIntersection, Subsets[shapes, {2}]] /.
EmptyRegion[2] -> Nothing;
overlappingArea = Total[Map[Area, shapePairs]];
areaRatio = overlappingArea/totalArea;
Print["Overlap ratio is ", areaRatio, "( ", overlappingArea, " / ",
totalArea, " )"]; Print[Graphics[shapes, Axes -> True]];
{areaRatio, overlappingArea, totalArea}]
m = 125;
r = 100;
pt[i_] := RandomReal[{-5000, 5000}, 2];
allCircles = Table[Disk[pt[i], r], {i, m}];
AbsoluteTiming[overlapAreaModule[allCircles]]
pt
,r
andm
$\endgroup$