Q:

Calculate coordinates of circle that best approximates intersection between 2 circles

I have two circles that could intersect, and if is it the case, I would calculate the coordinates of the largest circle that approximates that intersection area.
I drew a sketch in svg to represent the problem:
<svg width="400" height="400">
    <line x1="85" y1="50" x2="140" y2="70" stroke="rgb(50,50,50)" stroke-width="1" />
    <circle cx="85" cy="50" r="50" stroke="rgba(50,50,50,0.8)" stroke-width="1" fill="rgba(0,0,150,0.3)" />
    <circle cx="140" cy="70" r="40" stroke="rgba(50,50,50,0.8)" stroke-width="1" fill="rgba(150,0,0,0.3)" />

    <circle cx="117" cy="62" r="16" stroke="rgba(50,50,50,0.8)" stroke-width="1" fill="rgba(00,150,0,0.3)" />
</svg>

you can try it online here: http://www.w3schools.com/svg/tryit.asp?filename=trysvg_line .
What I would, having the first two circles, is the center and the radius of third one (that in the example I drew by hand).

A:

Let
A, r1 = center, radius of first circle
B, r2 = center, radius of second circle

be the given input data and
C, r3 = center, radius of third circle

be the largest circle that fits into the intersection of the first two circles.
Denote by
D = intersection point of first with third circle
E = intersection point of second with third circle

D and E are points on the line connecting the centers A and B. D has distance r1 from
A and E has distance r2 from B. Therefore
D = A + r1 * (B - A)/dist(A, B)
E = B - r2 * (B - A)/dist(A, B)

from which follows
C  = (D + E)/2    = (A + B + (r1 - r2)*(B - A)/dist(A, B)) / 2
r3 = dist(D, E)/2 = (r1 + r2 - dist(A, B)) / 2

If r3 < 0 then the circles do not intersect at all.
(The above calculation assumes that none of the circles lies completely within the other circle.)

