[Math] Math and equations for external tangent lines between two dissimilar circles

geometry

I am trying to determine the maths behind drawing a line from the top of one circle to the top of another (and bottom to bottom). I am doing this for a programmatically generated CAD file, I currently have the software implemented that will just connect the top most points of each circle, but as you can see in the pictures below it does not look right.

Here is how the code performs for equal sized circles, a line from the top to top makes a nice looking figure.

enter image description here

Here is how the code performs for unequal sized circles, a line from the top to top looks a little off
enter image description here

I am trying to determine the tangent points on the circles to draw the lines between. As if you dropped a line onto the circles, I need the points where the line would rest at on each circle. In the picture below, I am drawing the red line currently, but I need the blue one.

enter image description here

From the picture you can see what values I have to work with. How might I go about finding the proper points?

EDIT: The proper jargon for what I want is external tangent lines. My issue now is I need the maths behind creating them so I can translate it into code.

EDIT2: I now have two main questions in bold below.


Following the link in the first edit on how to determine the external tangent lines of the circles, the first thing I need to do is determine the two points of intersection of the two temporary circles drawn to help us (The larger green dotted line circle, and the orange dotted line circle)

enter image description here

If the equation for the two circles are
$$(x-x_{green})^2 + (y-y_{green})^2 = r_{green}^2, \tag{Green}$$
$$(x-x_{orange})^2 + (y-y_{orange})^2 = r_{orange}^2. \tag{Orange}$$
Then the equation of the line that intersects the two is (As per this math.stack answer.)
$$-2x(x_{green}- x_{orange}) – 2y(y_{green} – y_{orange}) = (r_{green}^2 – r_{orange}^2) – (x_{green}^2 – x_{orange}^2) – (y_{green}^2 – y_{orange}^2).$$
The problem is I am not sure how to obtain the two intersection points from this equation.

So I did find these points, lets call the them
$$(r_{top}, s_{top}) \tag{Top}$$
$$(r_{bot}, s_{bot}) \tag{Bottom}$$
Given those two points and the center of the large green circle I can find an equation for line 1 and line 2

enter image description here

Respectively the equation of those two lines would be
$$(y_{green}-s_{top})=m_{top}(x_{green}-r_{top}) \quad where \quad m_{top}=\frac{(s_{top}-x_{green})}{(r_{top}-y_{green})} \tag{Line 1}$$
$$(y_{green}-s_{bot})=m_{bot}(x_{green}-r_{green}) \quad where \quad m_{bot}=\frac{(s_{bot}-x_{green})}{(r_{bot}-y_{green})} \tag{Line 2}$$

After I have the equation for these two lines I need to find the point on both where they intersect the main circle $r_{large}$ (From the very first picture). Given that the equation for the circle $r_{large}$ is

$$(x-x_{large})^2 + (y-y_{large})^2 = r_{large}^2, \tag{Largest of two main circles}$$

I would need to solve the equation of the two lines each for x or y, lets go with y

$$y_{top}=m_{top}(x_{green}-r_{top})+s_{top}$$
$$y_{bot}=m_{bot}(x_{green}-r_{bot})+s_{bot}$$

Now we can plug those into the equation for the main circle

$$(x-x_{large})^2+(y_{top}-y_{large})^2=r_{large}^2$$
$$(x-x_{large})^2+(y_{bot}-y_{large})^2=r_{large}^2$$

Then we can solve for x

$$x=x_{top} = \sqrt{r_{large}^2-(y_{top}-y_{large})^2}+x_{large}$$
$$x=x_{bot} = \sqrt{r_{large}^2-(y_{bot}-y_{large})^2}+x_{large}$$

Which you give us $(x_{top},y_{top})$ and $(x_{bot},y_{bot})$, these are the top and bottom points on the largest circle that lie on the external tangent lines of the two circles.

Now I thought given these two points the two tangent points for the smaller circle would be easier to find. If using pencil and paper, all you need to do is draw perpendicular lines from the two tangent points. But to get the actual values is more difficult.

Where would I even start to find the other set of tangent points on the small circle?

Final Edit:

In the end I found this website which helped a lot. It has a lot of different function defined in C for geometric actions. But here is what I ended up with 🙂

enter image description here

Best Answer

Here is another approach that may be quicker and is accessible without vector calculus.

The two circles have equations $\left(x-h\right)^2+\left(y-k\right)^2=r^2$ and $\left(x-u\right)^2+\left(y-v\right)^2=s^2$

We'll just search for the point $\left(x_1,y_1\right)$ that is on the $\left(h,v\right)$-circle. Once we have that, it's easy to see that the slope of the tangent line is $\frac{y_1-k}{x_1-h}$. So the tangent line will have equation $$y=\frac{y_1-k}{x_1-h}\left(x-x_1\right)+y_1$$

Assume for a second that we have found $x_1$ and $y_1$. How will this line meet the second circle? We can make the substitution for $y$ into the second circle's equation: $$\begin{align} \left(x-u\right)^2+\left(y-v\right)^2&=s^2\\ \left(x-u\right)^2+\left(\frac{y_1-k}{x_1-h}\left(x-x_1\right)+y_1-v\right)^2&=s^2\\ \left(x-u\right)^2\left(x_1-h\right)^2+\left(\left(y_1-k\right)\left(x-x_1\right)+\left(y_1-v\right)\left(x_1-h\right)\right)^2&=s^2\left(x_1-h\right)^2\\ \end{align}$$

This is a quadratic equation in $x$, and $x$-values that solve it are $x$-values for a point on the second circle where the line will intersect it. We want this equation to have precisely one solution, since we want the line to be tangent to the second circle. So we rearrange the equation so that we can cleanly see the discriminant and set it equal to $0$.

$$\begin{align} x^2\left(\left(x_1-h\right)^2+\left(y_1-k\right)^2\right)+x\left(-2u\left(x_1-h\right)^2-2x_1\left(y_1-k\right)^2+2\left(y_1-k\right)\right)\\ {}+u^2\left(x_1-h\right)^2+\left(y_1-k\right)^2x_1^2-2x_1\left(y_1-k\right)\left(y_1-v\right)\left(x_1-h\right)+\left(y_1-v\right)^2\left(x_1-h\right)^2\\ {}-s^2\left(x_1-h\right)^2&=0\\ \end{align}$$

And so along with satisfying $\left(x_1-h\right)^2+\left(y_1-k\right)^2=r^2$, $x_1$ and $y_1$ satisfy $$\begin{align} \left(B\right)^2-4\left(A\right)\left(C\right)&=0 \end{align}$$

where $A$, $B$, and $C$ are evident in the quadratic equation above. So that makes two equations in two unknowns $x_1$ and $y_1$. Solving these two equations will give you one point on the first circle, from which you can determine a slope and plot the tangent line.

Related Question