geometry
circle overlap
area calculation
mathematical modeling
spatial analysis

Combined area of overlapping circles

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

For two circles, the combined covered area is the sum of both circle areas minus the region they share. The challenge is that the overlap depends on the distance between the centers, so the formula changes across three geometric cases: no overlap, one circle fully inside the other, and partial overlap.

Core Sections

Start from inclusion-exclusion

The union area of two sets follows a simple rule:

  • area of circle one
  • plus area of circle two
  • minus the overlap area counted twice

For circles with radii r1 and r2, the union area is:

text
union = pi * r1^2 + pi * r2^2 - overlap

So the real work is computing overlap correctly.

Handle the easy cases first

Before using any trigonometry, check the relative position of the circles. Let d be the distance between their centers.

  1. If d >= r1 + r2, the circles do not intersect. The overlap is zero.
  2. If d <= abs(r1 - r2), one circle lies completely inside the other. The overlap is the area of the smaller circle.
  3. Otherwise, the circles partially overlap and you need the lens-area formula.

These checks are important because the full formula is less numerically stable near the edge cases.

Use the partial-overlap formula

For the partial-overlap case, the shared region is made of two circular segments. The standard formula is:

text
overlap = r1^2 * acos((d^2 + r1^2 - r2^2) / (2 * d * r1))
        + r2^2 * acos((d^2 + r2^2 - r1^2) / (2 * d * r2))
        - 0.5 * sqrt((-d + r1 + r2) * (d + r1 - r2) * (d - r1 + r2) * (d + r1 + r2))

Once you have that overlap value, subtract it from the total of the two circle areas.

Implement it in Python

python
1import math
2
3
4def combined_area(x1, y1, r1, x2, y2, r2):
5    d = math.hypot(x2 - x1, y2 - y1)
6    area1 = math.pi * r1 * r1
7    area2 = math.pi * r2 * r2
8
9    if d >= r1 + r2:
10        return area1 + area2
11
12    if d <= abs(r1 - r2):
13        return max(area1, area2)
14
15    term1 = r1 * r1 * math.acos((d * d + r1 * r1 - r2 * r2) / (2 * d * r1))
16    term2 = r2 * r2 * math.acos((d * d + r2 * r2 - r1 * r1) / (2 * d * r2))
17    term3 = 0.5 * math.sqrt(
18        (-d + r1 + r2) *
19        (d + r1 - r2) *
20        (d - r1 + r2) *
21        (d + r1 + r2)
22    )
23
24    overlap = term1 + term2 - term3
25    return area1 + area2 - overlap
26
27
28print(combined_area(0, 0, 3, 5, 0, 4))

This function returns the total covered area of both circles together, not the overlap by itself.

Understand what the formula is measuring

The two acos terms describe the areas of the two sectors cut by the chord of intersection. The square-root term subtracts the kite-shaped region that was counted inside both sectors. That decomposition is why the result is the lens-shaped overlap area.

You do not need to memorize the derivation to use the formula correctly, but knowing the geometric pieces makes debugging much easier.

Numerical considerations

Floating-point rounding can push the acos input slightly outside the valid range from -1 to 1, especially when circles nearly touch. In production code, clamp the argument before calling acos.

python
def clamp(value, low, high):
    return max(low, min(high, value))

That small defensive step can prevent domain errors in edge cases.

More than two circles is a different problem

The neat closed-form solution above is specific to two circles. For many circles, exact union area becomes much more complex. At that point, people often switch to computational geometry libraries, plane sweep methods, polygon approximation, or Monte Carlo estimation depending on the precision requirements.

Common Pitfalls

  • Applying the partial-overlap formula without first checking the no-overlap and containment cases.
  • Returning the overlap area when the real question asks for the combined union area.
  • Forgetting that one circle entirely inside another means the union is just the larger circle’s area.
  • Ignoring floating-point edge cases near tangency, which can make acos fail unexpectedly.
  • Assuming the two-circle formula scales directly to many circles, even though that becomes a more complex geometric problem.

Summary

  • The combined area is area1 + area2 - overlap.
  • Always distinguish between no overlap, full containment, and partial overlap.
  • The partial-overlap case uses a standard lens-area formula based on acos and a square-root term.
  • Implement edge-case checks before the full formula for correctness and stability.
  • For more than two circles, you usually need a different computational approach.

Course illustration
Course illustration

All Rights Reserved.