I'm trying to find the lines tangent to two circles. I've seen several examples but with poorlyy explained methods. Given the circle
$(x-x_{0})^2+(y-y_{0})^2=r_{1}^2$
and the the line equation
$y=ax+b$
one of the method is based on the relation
$(ax_{0}+b-y_{0})^2=(a^2+1)r_{1}^{2}$
Can you tell me what relation is this? How it was obtained? Thank you.

Consider a circle $C$ $$ (X-x_0)^2+(Y-y_0)^2=r^2 $$ and a line $L$ given by $Y=aX+b$. Then if $C$ and $L$ intersect each other at a point $(x,y)$, then since $(x,y)\in L$ you have $y=ax+b$ and since $(x,y)\in C$ we have $(x-x_0)^2+(ax+b-y_0)^2=r^2$. Therefore $$ \Longrightarrow (a^2+1)x^2 +2x[x_0+a(b-y_0)]+x_0^2+(b-y_0)^2-r^2=0 $$ This is a quadratic equation with solutions $$ x=\frac{-(x_0+a(b-y_0)\pm \sqrt{(x_0+a(b-y_0))^2+(a^2+1)(r^2-x_0^2-(b-y_0)^2)}}{a^2+1} $$ The $\Delta$ of this quadratic equation (the term under the square root) must vanish if the line $L$ is tangent to $C$ because otherwise the line intersects $C$ at two points ($\Delta>0$) or no points $(\Delta<0)$. Hence we must have $$ \begin{aligned} 0=\Delta=2ax_0(b-y_0)&=(x_0+a(b-y_0))^2+(a^2+1)(r^2-x_0^2-(b-y_0)^2)\\ &= x_0^2+2ax_0(b-y_0)+a^2(b-y_0)^2+(a^2+1)(r^2-x_0^2-(b-y_0)^2)\\ &=(1+a^2)r^2-(b-y_0)^2-a^2x_0^2+2ax_0(b-y_0)\\ &=(1+a^2)r^2 - (ax_0+b-y_0)^2\Longrightarrow\\ (ax_0+b-y_0)^2&=(1+a^2)r^2 \end{aligned} $$ What this means is that the line $L$ given via $y=ax+b$ is tangent to $C$ if and only if $a,b$ satisfy $$ (ax_0+b-y_0)^2=(1+a^2)r^2 $$ Now if $C'$ is another circle with center $O'=(x'_0,y'_0)$ and radius $r'$, and if $L$ is also tangent to $C'$ then $a,b$ are the mutual solution to the equations $$ \begin{cases} (ax_0+b-y_0)^2=(1+a^2)r^2\\ (ax_0'+b-y_0')^2=(1+a^2)r'^2 \end{cases} $$ Solve this to find your tangent line. This is of course assuming the tangent line is not $x=c$ because we took our line equation to be $y=ax+b$. You need to carry out similar but simpler analysis to check if $x=0$ is a double tangent.