Geometry
Circle Intersections
Math Problem Solving
Analytical Geometry
Intersection Points

Circle-circle intersection points

Master System Design with Codemia

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

Introduction

Finding the intersection points of two circles is a standard geometry problem with practical uses in graphics, robotics, collision logic, and geometric solvers. The answer depends on the relative positions of the circle centers and radii: there may be no intersection points, exactly one tangency point, two intersection points, or infinitely many points if the circles are identical.

Core Sections

Start with the geometry cases

Let the circles have centers (x1, y1) and (x2, y2) with radii r1 and r2. Let d be the distance between the centers.

The main cases are:

  • if d > r1 + r2, the circles are too far apart and do not intersect
  • if d < |r1 - r2|, one circle lies inside the other with no intersection
  • if d == r1 + r2 or d == |r1 - r2|, the circles are tangent and have one intersection point
  • if |r1 - r2| < d < r1 + r2, they intersect in two points
  • if d == 0 and r1 == r2, the circles are coincident and have infinitely many intersection points

Those case checks should happen before any coordinate formula, because they tell you which geometric situation you are solving.

The standard coordinate formula

The usual derivation builds a point on the line between the two centers and then offsets perpendicular to that line.

Define:

  • 'a = (r1^2 - r2^2 + d^2) / (2d)'
  • 'h = sqrt(r1^2 - a^2)'

Then the base point on the center-to-center line is:

  • 'px = x1 + a * (x2 - x1) / d'
  • 'py = y1 + a * (y2 - y1) / d'

The intersection offsets are perpendicular to that line:

  • 'rx = -(y2 - y1) * (h / d)'
  • 'ry = (x2 - x1) * (h / d)'

So the two intersection points are:

  • '(px + rx, py + ry)'
  • '(px - rx, py - ry)'

If h == 0, those two expressions collapse to the same tangency point.

A Python implementation

python
1import math
2
3
4def circle_intersections(x1, y1, r1, x2, y2, r2):
5    dx = x2 - x1
6    dy = y2 - y1
7    d = math.hypot(dx, dy)
8
9    if d == 0 and r1 == r2:
10        return None  # infinitely many points
11    if d > r1 + r2:
12        return []
13    if d < abs(r1 - r2):
14        return []
15    if d == 0:
16        return []
17
18    a = (r1 * r1 - r2 * r2 + d * d) / (2 * d)
19    h_sq = r1 * r1 - a * a
20    if h_sq < 0:
21        h_sq = 0
22    h = math.sqrt(h_sq)
23
24    px = x1 + a * dx / d
25    py = y1 + a * dy / d
26
27    rx = -dy * (h / d)
28    ry = dx * (h / d)
29
30    p1 = (px + rx, py + ry)
31    p2 = (px - rx, py - ry)
32
33    if h == 0:
34        return [p1]
35    return [p1, p2]
36
37
38print(circle_intersections(0, 0, 5, 4, 0, 3))

This function returns:

  • '[] for no intersection'
  • one point for tangency
  • two points for a normal intersection
  • 'None for coincident circles'

Example: two intersection points

Take these circles:

  • center (0, 0), radius 5
  • center (4, 0), radius 3

The result is approximately (4, 3) and (4, -3).

That makes sense geometrically because the circles meet symmetrically above and below the x-axis. A worked example like this is useful because it helps confirm the sign and offset logic in the formula.

Numerical stability matters in code

In floating-point code, values that should theoretically be zero may become tiny negative numbers due to rounding. That is why the implementation above clamps h_sq to zero before taking the square root.

Without that guard, nearly tangent circles can produce a domain error in sqrt even though the geometry says the circles should touch.

That small defensive step makes the function much more usable in graphics and simulation code.

Common Pitfalls

  • Jumping straight into the coordinate formula without checking the geometry cases can lead to division or square-root issues.
  • Forgetting the coincident-circle case misses the situation with infinitely many intersection points.
  • Failing to handle floating-point roundoff near tangency can produce a negative value inside the square root by accident.
  • Returning two identical points for tangency instead of collapsing to one intersection makes downstream code more awkward.
  • Mixing up the perpendicular offset signs can reflect the points incorrectly even when the rest of the derivation is right.

Summary

  • Two circles can have zero, one, two, or infinitely many intersection points depending on distance and radii.
  • The standard solution uses the center distance, a base point on the center line, and a perpendicular offset.
  • Tangency is the special case where the perpendicular offset length becomes zero.
  • A robust implementation should check geometry cases first and guard against floating-point roundoff.
  • Once the cases are handled cleanly, circle-circle intersection code is compact and reliable.

Course illustration
Course illustration

All Rights Reserved.