Position 3 circles so their circumferences are always touching

154 Views Asked by At

I have 3 circles with radii r1, r2, r3.

I place the first circle at (r1, r1) on x and y axis.

I then place the second at (A, r2), where A = ((r1 + r2)^2 + (r1 - r2)^2)^0.5

Now I want to place the 3rd circle r2 away from the centre of circle 2, so it rests on the circumference of circle 1.

The following diagram shows 3 circles in a possible configuration. d1 is the diameter of the red circle, d2 is the diameter of the green circle, and d3 is the diameter of the blue circle. What I need to know are the coords of the centre of the blue circle, or a and b.

The diagram may, however, be misleading because for small values of d2 and r2, the green circle tucks under the red circle.

diagram

Here is a codesandbox link that demonstrates what I mean, although the last circle is not working. codesandbox

I wish to assume that the circles are sorted in order of radius size, from biggest to smallest, although ideally it should not matter.

This is not really a code question because I can find the values iteratively with code, but would prefer a formula solution.

2

There are 2 best solutions below

0
On BEST ANSWER

3 circles tangent to each other

As shown in the diagram above, let $A$, $B$ and $C$ be the centers of the $3$ circles. Draw the lines $AC$ and $BC$ to join these centers. Since the circles are tangent to each other, these lines go through the points where they are tangent, so each length is the sum of the circle radii, i.e.,

$$|AC| = r_1 + r_3 \tag{1}\label{eq1B}$$

$$|BC| = r_2 + r_3 \tag{2}\label{eq2B}$$

Assign the point coordinates to be $A(x_1,y_1)$, $B(x_2,y_2)$ and $C(x_3,y_3)$. With \eqref{eq1B} and \eqref{eq2B}, using these coordinates in the squares of the lengths of $|AC|$ and $|BC|$ gives

$$\begin{equation}\begin{aligned} (x_1 - x_3)^2 + (y_1 - y_3)^2 & = (r_1 + r_3)^2 \\ x_1^2 - 2x_1x_3 + x_3^2 + y_1^2 - 2y_1y_3 + y_3^2 & = r_1^2 + 2r_1r_3 + r_3^2 \end{aligned}\end{equation}\tag{3}\label{eq3B}$$

$$\begin{equation}\begin{aligned} (x_2 - x_3)^2 + (y_2 - y_3)^2 & = (r_2 + r_3)^2 \\ x_2^2 - 2x_2x_3 + x_3^2 + y_2^2 - 2y_2y_3 + y_3^2 & = r_2^2 + 2r_2r_3 + r_3^2 \end{aligned}\end{equation}\tag{4}\label{eq4B}$$

Next, \eqref{eq3B} minus \eqref{eq4B} gives

$$\begin{equation}\begin{aligned} & x_1^2 - x_2^2 + 2(x_2 - x_1)x_3 + y_1^2 - y_2^2 + 2(y_2 - y_1)y_3 = r_1^2 - r_2^2 + 2(r_1 - r_2)r_3 \\ & 2(x_2 - x_1)x_3 + 2(y_2 - y_1)y_3 = r_1^2 - r_2^2 + 2(r_1 - r_2)r_3 - x_1^2 + x_2^2 - y_1^2 + y_2^2 \\ & c_1x_3 + c_2y_3 = c_3 \end{aligned}\end{equation}\tag{5}\label{eq5B}$$

where, to make the algebra easier to deal with, I have set

$$c_1 = 2(x_2 - x_1) \tag{6}\label{eq6B}$$

$$c_2 = 2(y_2 - y_1) \tag{7}\label{eq7B}$$

$$c_3 = r_1^2 - r_2^2 + 2(r_1 - r_2)r_3 - x_1^2 + x_2^2 - y_1^2 + y_2^2 \tag{8}\label{eq8B}$$

In \eqref{eq3B}, move the $x_1^2 + y_1^2$ terms to the right to get

$$-2x_1x_3 + x_3^2 - 2y_1y_3 + y_3^2 = c_4 \tag{9}\label{eq9B}$$

where

$$c_4 = r_1^2 + 2r_1r_3 + r_3^2 - x_1^2 - x_2^2 \tag{10}\label{eq10B}$$

Assuming $x_2 \neq x_1$, so $c_1 \neq 0$ in \eqref{eq6B}, you can get from \eqref{eq5B} that

$$x_3 = \frac{c_3 - c_2y_3}{c_1} \tag{11}\label{eq11B}$$

Substituting this into \eqref{eq9B} gives

$$\begin{equation}\begin{aligned} & -2x_1\left(\frac{c_3 - c_2y_3}{c_1}\right) + \left(\frac{c_3 - c_2y_3}{c_1}\right)^2 - 2y_1y_3 + y_3^2 = c_4 \\ & -\frac{2x_1c_3}{c_1} + \left(\frac{2x_1c_2}{c_1}\right)y_3 + \frac{c_3^2}{c_1^2} - \left(\frac{2c_2c_3}{c_1^2}\right)y_3 + \left(\frac{c_2^2}{c_1^2}\right)y_3^2 - 2y_1y_3 + y_3^2 = c_4 \\ & \left(\frac{c_2^2}{c_1^2} + 1\right)y_3^2 + \left(\frac{2x_1c_2}{c_1} - \frac{2c_2c_3}{c_1^2} - 2y_1\right)y_3 - \frac{2x_1c_3}{c_1} + \frac{c_3^2}{c_1^2} - c_4 = 0 \\ & c_5y_3^2 + c_6y_3 + c_7 = 0 \end{aligned}\end{equation}\tag{12}\label{eq12B}$$

where, once again, to keep the algebra somewhat simpler, I've set

$$c_5 = \frac{c_2^2}{c_1^2} + 1 \tag{13}\label{eq13B}$$

$$c_6 = \frac{2x_1c_2}{c_1} - \frac{2c_2c_3}{c_1^2} - 2y_1 \tag{14}\label{eq14B}$$

$$c_7 = -\frac{2x_1c_3}{c_1} + \frac{c_3^2}{c_1^2} - c_4 \tag{15}\label{eq15B}$$

Using the quadratic formula in \eqref{eq12B} gives

$$y_3 = \frac{-c_6 \pm \sqrt{c_6^2 - 4c_5c_7}}{2c_5} \tag{16}\label{eq16B}$$

There are $2$ roots because circle $C$ could be located either below the tangent point between $A$ and $B$ or above it. Assuming you want the one below, choose the smaller root in \eqref{eq16B}. Finally, you can substitute that value into \eqref{eq11B} to get $x_3$. You will then have the coordinates of the center of the blue circle.

0
On

3 tangent circles

Note: I wrote this answer before I later realized there's a generally shorter & easier method, which I've shown in my other answer. However, I'm leaving this answer here for anybody who might be interested in it.

As shown in the diagram above, let $A$, $B$ and $C$ be the centers of the $3$ circles. Draw the lines $AB$, $AC$ and $BC$ to join these centers. Since the circles are tangent to each other, these lines go through the points where they are tangent, so each length is the sum of the corresponding circle radii, i.e.,

$$|AB| = r_1 + r_2 \tag{1}\label{eq1A}$$

$$|AC| = r_1 + r_3 \tag{2}\label{eq2A}$$

$$|BC| = r_2 + r_3 \tag{3}\label{eq3A}$$

Next, draw the line perpendicular to $AB$ which goes through $C$, with $D$ being where this line crosses $AB$, and $|CD| = h$. Also let $x$ be the "length" of $AD$ and $y$ be the "length" of $DB$. I'm using quotes around length since $x$ or $y$ could be negative as $D$ may potentially not be between $A$ and $B$. In any case, using \eqref{eq1A}, this gives

$$x + y = r_1 + r_2 \iff y = r_1 + r_2 - x \tag{4}\label{eq4A}$$

Using the Pythagorean theorem on $\triangle ADC$ and $\triangle BDC$ gives

$$x^2 + h^2 = (r_1 + r_3)^2 = r_1^2 + 2r_1r_3 + r_3^2 \tag{5}\label{eq5A}$$

$$y^2 + h^2 = (r_2 + r_3)^2 = r_2^2 + 2r_2r_3 + r_3^2 \tag{6}\label{eq6A}$$

Substituting \eqref{eq4A} into \eqref{eq6A} gives

$$\begin{equation}\begin{aligned} & ((r_1 + r_2) - x)^2 + h^2 = r_2^2 + 2r_2r_3 + r_3^2 \\ & (r_1 + r_2)^2 - 2(r_1 + r_2)x + x^2 + h^2 = r_2^2 + 2r_2r_3 + r_3^2 \\ & r_1^2 + 2r_1r_2 + r_2^2 - 2(r_1 + r_2)x + x^2 + h^2 = r_2^2 + 2r_2r_3 + r_3^2 \\ & x^2 + h^2 = 2(r_1 + r_2)x - r_1^2 - 2r_1r_2 + 2r_2r_3 + r_3^2 \end{aligned}\end{equation}\tag{7}\label{eq7A}$$

Substituting \eqref{eq7A} into \eqref{eq5A} results in

$$\begin{equation}\begin{aligned} 2(r_1 + r_2)x - r_1^2 - 2r_1r_2 + 2r_2r_3 + r_3^2 & = r_1^2 + 2r_1r_3 + r_3^2 \\ 2(r_1 + r_2)x & = 2r_1^2 + 2r_1r_2 - 2r_2r_3 + 2r_1r_3 \\ (r_1 + r_2)x & = (r_1 + r_2)r_1 + (r_1 - r_2)r_3 \\ x & = r_1 + \frac{(r_1 - r_2)r_3}{r_1 + r_2} \end{aligned}\end{equation}\tag{8}\label{eq8A}$$

Substituting this into \eqref{eq5A} gives

$$\begin{equation}\begin{aligned} h^2 & = r_1^2 + 2r_1r_3 + r_3^2 - x^2 \\ & = r_1^2 + 2r_1r_3 + r_3^2 - \left(r_1 + \frac{(r_1 - r_2)r_3}{r_1 + r_2}\right)^2 \\ & = r_1^2 + 2r_1r_3 + r_3^2 - r_1^2 - \frac{2(r_1 - r_2)r_1 r_3}{r_1 + r_2} - \frac{(r_1 - r_2)^2 r_3^2}{(r_1 + r_2)^2} \\ & = 2r_1r_3 + r_3^2 - \frac{2(r_1 - r_2)r_1 r_3}{r_1 + r_2} - \frac{(r_1 - r_2)^2 r_3^2}{(r_1 + r_2)^2} \end{aligned}\end{equation}\tag{9}\label{eq9A}$$

You can now take the square root to get $h$ although, as explained below, you likely don't really need to as you may just use $h^2$ in the rest of the process.

Here is an outline of how to finish so you can determine the coordinates of $C$ based on those of $A$ and $B$. Define $A(x_1,y_1)$ and $B(x_2,y_2)$. Then the line between $A$ and $B$ can be specified parametrically with $f(t) = (x_1 + t(x_2 - x_1), y_1 + t(y_2 - y_1)$, with $A = f(0)$ and $B = f(1)$. Using the distance of a line (with the square of it being easier to deal with), you can determine the value of $t$ where $D$ is located, keeping in mind that $t \lt 0$ if $x \lt 0$, i.e., $D$ is to the left of $A$.

Next, the slope of $AB$, assuming it's not exactly vertical, is rise over run, i.e., $m = \frac{y_2 - y_1}{x_2 - x_1}$. Since $CD$ is perpendicular to $AB$, its slope is the negative reciprocal, i.e., $-\frac{1}{m}$. You can represent the equation of the line on which $CD$ lies as $y = -\frac{x}{m} + b$. Using the coordinates of $D$, you can determine $b$.

Finally, you can determine the coordinates of $C$, call it $C(x_3,y_3)$, by using that it lies on $CD$, i.e., $y_3 = -\frac{x_3}{m} + b$, and its distance from $D$ is $h$ (and, once again, it'll be easier to use distance squared being $h^2$). Don't forget you'll get $2$ possible results, one for where $C$ is below $AB$ as shown, and one where its above $AB$, i.e., where $C$ is located above the circles $A$ and $B$ on the top of them, so you will need to determine which point you want to use.