3

To give an idea of what my end goal looks like visually:

Touching circles

You start with one circle. You add a second circle, making it touch the first circle at some point. For each successive circle (for which we know the radius) to be added, there should be exactly two ways for it to touch the previous two (for which we know the coordinates of their centers and their radii). Is there a formula that expresses these solutions?

lioness99a
  • 4,943

2 Answers2

3

We have two circles, with radii $r_1$ and $r_2$ and centres $(x_1,y_1)$ and $(x_2 ,y_2)$ respectively. These two circles touch, so we can say that the distance between the two centres is $$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2} =r_1+r_2$$

We have a third circle with known radius $r_3$ and we want to find its possible centres $(x_3,y_3)$.

We know that the distance between the centre of circle $1$ and $3$ will be $$\sqrt{(x_1-x_3)^2+(y_1-y_3)^2} = r_1+r_3$$ and the distance between the centre of circle $2$ and $3$ will be $$\sqrt{(x_2-x_3)^2+(y_2-y_3)^2} = r_2+r_3$$

We can see this in the below diagram:

circles

We can the use these two equations to solve for $(x_3,y_3)$

\begin{align}\sqrt{(x_1-x_3)^2+(y_1-y_3)^2} &= r_1+r_3\tag{1}\\ \sqrt{(x_2-x_3)^2+(y_2-y_3)^2} &= r_2+r_3\tag{2}\end{align}

as we know the values of all the other variables, $x_1,y_1,r_1,x_2,y_2,r_2,r_3$


Example:

We have a circle centre $(1,1)$, radius $2$, and a circle centre $(4,5)$, radius $3$. We want to add another circle of radius $1$.

We input all these values into the formulae above:

\begin{align}\sqrt{(1-x_3)^2+(1-y_3)^2} &= 3\tag{1}\\ \sqrt{(4-x_3)^2+(5-y_3)^2} &= 4\tag{2}\end{align}

We can solve these for $(x_3,y_3)$ to find that the two possible centres are $$(4,1)\text{ and }\left(\frac 4{25},\frac {97}{25}\right)$$

I'll leave it to you to plot these $4$ circles and see that it works!

lioness99a
  • 4,943
  • Perfect. Thank you for such a well written explanation! – tobakudan May 23 '17 at 11:26
  • Do you know if there is a way to determine the circle between the two possible ones such that when you draw a line from the first circle's center to the second circle's center, the third circle falls to the left of that line (facing the direction the line was drawn in) so that the choice of the third circle is deterministic? (Edit) Actually realized it's fairly simple - just use the graph of the line and determine on which side of the line the centers of the circles lie on :p – tobakudan May 23 '17 at 11:30
  • @tobakudan No worries, and yes, your thoughts are correct with regards to the circle being on a specific side of the line – lioness99a May 23 '17 at 14:51
  • 1
    @tobakudan Examine the sign of the triple product $C_1\cdot C_2\times C_3$ of the three circle centers, which is also the determinant of the matrix that has these points are rows or columns. If it’s positive, the points are listed in counterclockwise order—the third point is to the “left’ of $C_1$ and $C_3$. Therefore, choose the center for which this product is positive. – amd May 23 '17 at 19:45
  • Would you mind explaining how to solve such an equation? I need to code exactly that for a game and unfortunately, it's been too much time I did that in school to remember exactly the steps... Or maybe would you have a link which would explain the process? – Emidee Oct 19 '19 at 16:55
1

Let $C_1$, $r_1$ and $C_2$, $r_2$ be the centers and radii of the two existing circles, and $r$ the radius of the tangent circles. We want to find the center $C$ of the tangent circle that’s counterclockwise from $\overrightarrow{C_1C_2}$.

Consider the triangle $\triangle{C_1C_2C}$. Let $B$ be the foot of the altitude from $C$. enter image description here

By the Pythagoran theorem, $CC_1^2-BC_1^2=CC_2^2-BC_2^2$. Setting $d=BC_1$ and substituting the known side lengths, this equation becomes $$(r+r_1)^2-d^2=(r+r_2)^2-(r_1+r_2-d)^2.$$ Solving this for $d$ gives $$d={r_1(r+r_1)-r_2(r-r_1)\over r_1+r_2}\tag1$$ and the altitude $BC=h=\sqrt{(r+r_1)^2-d^2}=\sqrt{(r+r_2)^2-d^2}$. Set $\vec u={C_2-C_1\over r_1+r_2}$ (the unit vector that points from $C_1$ to $C_2$) and $\vec v=\operatorname{rot}(\vec u)=\langle -u_y,u_x\rangle$ ($\vec u$ rotated 90° counterclockwise). Then $$C=C_1+d\vec u+h\vec v.\tag2$$ If you’re coding this up, it might be more convenient to absorb the normalization factor $r_1+r_2$ into the triangle side lengths, i.e., $C=C_1+{d\over r_1+r_2}(C_2-C_1)+{h\over r_1+r_2}\operatorname{rot}(C_2-C_1)$.

amd
  • 53,693