# Angle of first circle where it intersects second circle

First, some background. I'm writing an application which a bit more mathematically challenging than what I'm used to.

I have two circles that overlap (not just touch, I mean there are two intersect points):

     XXX     YYY
XX | XX YY | YY
X   |   *   |   Y
X    |  Y X  |    Y
X    |  Y X  |    Y
X     | Y   X |     Y
X     C Y   X C     Y
X       Y   X       Y
X       Y X       Y
X       Y X       Y
X       *       Y
XX   XX YY   YY
XXX     YYY


There are actually four circles, two with a smaller radius so that each two make a doughnut shape (two doughnuts are identically sized and share the same y-coordinate for their center) - think of a curve running along the inside and the outside of the X and Y curves above. All four circles overlap with two intersects.

Currently, I'm just drawing the four circles so that the intersect points criss-cross, sort of like the # character.

For example, the center bit from the above diagram would be:

 rest of
left      *-----------------
<- circle  / -> rest of       \
\    \  /    /   right         \
\    \/    /     circle        \
\   /\   /                     \
\ /  \ /                       \
X    X                         \
/ \  / \                         \
/   \/   \                         \
/    /\    \                        |
/    /  \    \                       |
|   |    |   |                       |
|   |    |   |                       |
|   |    |   |                       |
\    \  /    /                       |
\    \/    /                        /
\   /\   /                        /
\ /  \ /                        /
X    X                        /
/ \  / \                      /
/   \/   \                    /
/    /\    \                  /
/    /  \ \  \                /
*------------------


where the bits in the intersects are still solid lines.

What I'm trying to do is draw eight arcs rather than four circles, so that the intersects are clear as per:

\    \  /    /
\    \/    /
\        /
\      /
|    |
/      \
/        \
/    /\    \
/    /  \    \
|   |    |   |
|   |    |   |
|   |    |   |
\    \  /    /
\    \/    /
\        /
\      /
|    |
/      \
/        \
/    /\    \
/    /  \    \


To do that, I need to know where the circles intersect but not as a point, since the arc drawing function expects a starting angle and a sweep (so {start = 0, sweep = 90} would give me the top right quadrant).

Rather I need to know the angle of the intersect point. From the first diagram above, 0 degrees is the vertical line and the sweep is clockwise, so that 90 degrees is to the right. Once I can calculate the angle, I can just feed that into the arc-drawing function.

It has to work with circles of different sizes since i have to find intersects between inner and outer circles.

I'm relatively comfortable in turning angles and radii into (x,y) coordinates using trig, it's just going back the other way is causing me problems - it's been 30 years and a lot of red wine since I did this stuff in school :-)

-

If you draw the line connecting the centers, let $r_1$ and $r_2$ be the radii of the circles, and $d$ the distance between the centers (which should be less than $r_1+r_2$ in your case) you can find the angle between the line joining the centers and the intersection point using the cosine law. Draw the triangle with the intersection point. The angle at the center of the $r_1$ circle is found from $(r_2)^2=(r_1)^2+d^2-2dr_1\cos \theta$