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 + r2ord == |r1 - r2|, the circles are tangent and have one intersection point - if
|r1 - r2| < d < r1 + r2, they intersect in two points - if
d == 0andr1 == 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
This function returns:
- '
[]for no intersection' - one point for tangency
- two points for a normal intersection
- '
Nonefor coincident circles'
Example: two intersection points
Take these circles:
- center
(0, 0), radius5 - center
(4, 0), radius3
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.

