Straight line touching two circles - fixed to another straight line

I want to find a series of steps or equations, that if possible can be put into a spreadsheet to solve the general case of the following problem. A straight line length $(a+b)$ touches two circles, radius $r_1$ centre $(x_1,y_1)$ and radius $r_2$ centre $(x_2,y_2)$. The point $O$ of this line is fixed to another straight line equation $y=mx+c$ such that length from this line to the first circle is always $a$ and from this line to the second circle is always $b$. I wish to get the coordinates $(x_a, y_a)$ and $(x_b, y_b)$ at where the line touches each circle and also $(x_O,y_O)$ at where it intersects $y=mx+c$. So far I have only managed to get answers by trial and error and not by drawing or mathematical calculation. The smaller circle is not always inside the larger circle.

enter image description here

• Please attach a better image. The black background makes it almost impossible (for my old eyes) to decipher it. – zoli Mar 23 '17 at 22:23
• are the circle centers fixed? You have a four bar linkeage with a constraint that point O lies on a line. So the configuration is fully constrained with no degrees of freedom. Is this correct? – ja72 Mar 23 '17 at 22:31
• What is the interest of the line $y=mx+n$ and in particular the interest to have it described in this way (meaning of $m$ and $n$ ?). For me, it plays no role because it does not provide any new constraint on the problem. Am I right ? – Jean Marie Mar 23 '17 at 22:52
• Thankyou all. I have added a clearer image now. – Dez Mar 24 '17 at 14:02
• As drawn all parts are fixed. I need to do the calculation for the parts being in given fixed positions. (Known x1, y1, x2, y2, r1, r2, m, c, a and b). The parts drawn are moving parts and may be of different sizes hence the need for a general calculation. – Dez Mar 24 '17 at 14:13