# Using overlap area to determine distance between overlapping circles

I'm working on a simple, two-ring Venn Diagram in JavaScript where the area of the sections will be determined by the set size (mapping dataset count to area in pixels).

Group 1 area (a1) = 800

Group 2 area (a2) = 600

Overlap area (ab) = 100

From this I'm able to get the radiuses with:

$$r_1 = \sqrt{\frac{a_1}{\pi}}$$

I'm setting the y coordinates of these circles to an arbitrary number (window.innerHeight / 2). However, I'm having trouble determining the distance between the centers of the two circles so that the area of the overlap has an area of ab.

Questions:

1. Using the three area values (a1, a2, ab), the two radiuses (r1, r2), and a constant y value for the center of the circles, is it possible to determine the distance between the centers of the two circles (d)?

2. Would I be able to determine the distance between the centers of the circles to the point where the circles intersect? Ideally that would give me a d1 and d2 where d = d1 + d2 so I can use trigonomic functions to get the other values I might need.

3. What are the forumlas to determine d, d1, and d2?

Here's a visual of the desired product: link to Venn Diagram image

• I suspect that there’s not going to be a neat closed-form solution to this since the area of a circular segment is $\frac12R^2(\theta-\sin\theta)$, where $\theta$ is the segment’s angle of arc. – amd Mar 8 '18 at 22:33
• See the related question math.stackexchange.com/q/791975/265466 for the simple case $r_1=r_2$. Even then, you have to resort to a numerical approximation. – amd Mar 9 '18 at 2:12

The lenticular intersection of the two circles consists of two circular segments, the areas of which are given by the reasonably well-known formula $\frac12 R^2(\theta+\sin\theta)$, where $\theta$ is the angle of arc covered by the segment. The appearance of both an angle and a trig function of that angle in that expression doesn’t bode well for finding a nice closed-form solution.
Referring to the above illustration, the intersection area is equal to the sum of the areas of the two circular sectors less the area of the kite formed by the radii: $$\frac12 r_1\theta_1 + \frac12 r_2\theta_2 - hd. \tag 1$$ The altitude $h$ and the proportion $\lambda$ of the distance between the centers the the line of intersection are easily found via the Pythagorean theorem: $$r_1^2-\lambda^2d^2 = h^2 = r_2^2 - (1-\lambda)^2d^2$$ from which $$\lambda = {d^2+r_1^2-r_2^2 \over 2d^2} \tag 2$$ and $$1-\lambda = {d^2-r_1^2+r_2^2 \over 2d^2}. \tag 3$$ We also have $\cos{\frac{\theta_1}2} = {\lambda d\over r_1}$ and $\sin{\frac{\theta_1}2} = \frac h{r_1}$, and similarly for $\theta_2$. Solving for the two angles and substituting everything back into expression (1) produces a rather ugly expression for the intersection area in terms of $r_1$, $r_2$ and $d$. It involves inverse trig functions of functions of $d$ and the square root of a rational expression in $d$, so there’s little chance of a closed-form solution, however complex.
I think the best bet for your code is to compute numerical approximations to $d$ and $\lambda$. $d$ is bounded above by $r_1+r_2$ and below by $|r_1-r_2|$, so a simple binary search might work pretty well. You could make a first guess at $d$ by approximating the intersection area with the area of the inscribed kite and solving the resulting equation that doesn’t involve any inverse trig functions, but that solution is likely to be fairly complex, too, and I doubt that it would buy you much, if anything, in terms of computational efficiency.