Processing math: 100%

Overlapping circles

Question

Consider two circles of radii R and r whose centres are separated by a distance d.

Geometry of two overlapping circles

The area of overlap between them (assuming |Rr|dR+r) is given by the following formula, derived below.

A(d;R,r)=βR2+αr212r2sin2α12R2sin2β, where cosα=r2+d2R22rdandcosβ=R2+d2r22Rd.

Inverting this formula to find d for a given overlap area A=A0 cannot be achieved analytically, but a numerical solution can be found as the root of the function A(d;R,r)A0.

Write a Python function which takes arguments A, the target overlap area, and R and r the two circle radii and returns d, the distance between the circle centres giving overlap area A. Use, for example, brentq.


Derivation

First note that A=0 if dR+r: the circles do not intersect at all in this case. Also, A=π(min(R,r))2 if d|Rr|: the smaller circle is entirely enclosed in the larger in this case. For the case of partial overlap, |Rr|<d<R+r the area to find is shaded in the diagram below.

Geometry of ovelapping circles highlighting their area of intersection

The cosine formula gives the angles α and β:

cosα=r2+d2R22rdandcosβ=R2+d2r22Rd.

The required area may be found as the sum of the two circle segments cut off by the chord CD. For the circle centred at A in the diagram above, its segment is the area of the circular sector ACD minus the area of the triangle ACD:

With x=AE=Rcosβ and h=CE=Rsinβ, triangle ACD has area xh=R2cosβsinβ=12R2sin2β. The area of the circular sector ACD is simply βR2 with β measured in radians (the entire circle has area πR2 and we want the fraction β/2π of it).

Therefore, the shaded circular segment has area βR212R2sin2β.

Similarly, the area of the segment of the circle centred at B cut off by chord CD is αr212r2sin2α.

The total intersection area is therefore

A=αr2+βR212r2sin2α12R2sin2β.


Solution