Finding the equation of a line that is tangent to a circle, given the equation of the circle and a point on the line I was wondering how would you find the equation of a tangent line of a circle if you are given the equation of the circle and a point on the line. In general:

Given an equation of a circle, $(x-h)^2 + (y-k)^2 = r^2$, and a line $l$ that contains the point $P(a,b)$ and is tangent to the circle, find the equation of $l$.

From my work on the problem, I knew that there are three cases:

*

*$P(a,b)$ is in the interior of the circle.

*$P(a,b)$ is on the circle.

*$P(a,b)$ is in the exterior of the circle.

Obviously, the first one can be discarded since the line $l$ can't be a tangent if $P$ is in the interior the circle.
For the second case, this implies that the point of tangency is $P$. Therefore, in order to find the equation for $l$, I need to find its slope by finding the negative reciprocal of the slope $m$ of the line that contains the center of the circle, $(h,k)$, and the point $P$, since they and line $l$ are perpendicular to each other (in other words, find $\dfrac{-1}{m}$). After that, simply substitute $\dfrac{-1}{m}$ and $(a,b)$ in the point-slope form of the equation of a line.
I was particularly interested in the third case, where the point $P$ is outside the circle.
An example problem that I made was this:

Find the equation of a line tangent to a circle, whose equation is $(x-4)^2 + (y-4)^2 = 9$, if the point $P(1,-1)$ is on the tangent line.

From a rough sketch I made, it seems that there are two lines that I need to find the equation of. Using the sketch, the first tangent line was just the line $x=1$. My problem lies in finding the second one.
I let point $T(a,b)$ be the point of tangency of line $l$ and the circle.
Then, I tried finding the distance $d$ between $(1,-1)$ and $(a,b)$ by employing the Pythagorean Theorem on the right triangle that is formed by the points $P(1,-1), T(a,b)$, and the center of the circle, $C(4,4)$, since the tangent is perpendicular to the radius.
After solving, what I got was $$d = 5$$
From then on, I was stuck. I tried doing the same method I used in solving the second case, but it seemed that I looped back to where I started.
I tried another method by letting $y_1 = m(x-1)-1$ be the equation for the second tangent line and letting $y_2 = \dfrac{-1}{m}(x-4)+4$ be the line that is perpendicular to it at the point of tangency, and setting them equal to each other. But, I got overwhelmed and thought that there may be a better method.
I still don't know the answer to it now, or if it's even solvable (it seems that it is, though). But if you managed to figure it out, I would gladly appreciate it if you showed me how!
 A: For the example problem

Find the equation of a line tangent to a circle, whose equation is $(x-4)^2 + (y-4)^2 = 9$, if the point $P(1,-1)$ is on the tangent line.

I would use a different point whose tangent does not have infinite
slope. For example, $P(0,4).$ Thus, the two equations to solve are
$$ y= ax+4, \qquad (x-4)^2 + (y-4)^2 = 9. $$
Substitute the first equation into the second to get
$$ (x-4)^2 + (ax+4-4)^2 = x^2-8x+16 +a^2 x^2 = 9. $$
Simplify this to get
$$ (1+a^2)x^2 - 8x + 7 = 0. $$
Solve the quadratic to get
$$ x  = \frac{ 4 \pm \sqrt{9-7a^2}}{1+a^2}. $$
This gives two values for $\,x\,$ for the point of intersection
in general. However, for $\, 9-7a^2=0\,$ there is only a single
point of intersection, hence a tangent line. Thus, the two tangent
lines must be $\, y=\frac3{\pm\sqrt{7}}x+4. \,$ Check that the
point $P(0,4)$ is on both tangent lines. Check that the point
$\,P(\frac74,4+\frac34\sqrt{7})\,$ is both on the line
$\, y = \frac{3}{\sqrt{7}}x+4\,$ and the circle. Same with the
other tangent line but with $\,-\sqrt{7}.$
The general case for any circle and a point outside the circle is
very similar.
A: After some time, I found the answer to the example question!
My insight was to draw another circle, with its center at $P(1,-1)$ and find all points that intersect with the given circle, then find the slope of the points accordingly.
First, draw a diagram: the circle $(x-4)^2 + (y-4)^2 = 9$; its center $C(4,4)$; the point $P(1,-1)$; and the two lines containing $P$ that are tangent to the given circle at the point of tangencies, $T_1$ and $T_2$. Our goal is to find the coordinates of $T_1$ and $T_2$ to find the slope of each line.
$P$ and tangent to said circle at $T_1$ and $T_2$" />
Next, find $PT_2$.* We do this by finding $PC$ and $CT_2$ (which is the radius), then solve the right triangle:
$(PT_2)^2 + (CT)^2 = (PC)^2$
$(PT_2)^2 + (3)^2 = (\sqrt{(1-4)^2 + (-1-4)^2})^2 = (-3)^2 + (-5)^2 $
$(PT_2)^2 + 9 = 9 + 25 $
$(PT_2)^2 = 25$
$PT_2 = 5$
$PT_2$ by solving right triangle $PCT_2$" />
Now, we find the equation of the circle with center at $P$ and with radius 5: $(x-1)^2 + (y+1)^2 = 25$

We find the intersections of these two circles by solving this system of equations:
$$\begin{cases}
(x-4)^2 + (y-4)^2 = 9 \\ 
(x-1)^2 + (y+1)^2 = 25 \\ 
\end{cases}
$$
Which boils down to this quadratic equation:
$$
17x^2 - 109x + 92 = 0
$$
Solving it would yield:
$$
x = \frac{109 \pm 75}{34}
$$
or
$$
x = 1 \qquad or \qquad x = \frac{92}{17}
$$
Whose respective corresponding y-coordinates are
$$
y = 4 \qquad or\qquad y = \frac{23}{17}
$$
So, we have $T_1 = (1,4)$ and $T_2 = (\frac{92}{17}, \frac{23}{17})$. We just need to find the slopes of the lines and find their equations.
The slope of line $PT_1$ is undefined, so its equation is $$x = 1$$
The slope of line $PT_2$ is $\frac{\frac{23}{17} - (-1)}{\frac{92}{17} - 1} = \frac{40}{75} = \frac{8}{15}$. Its equation is therefore:
$$
y+1 = \frac{8}{15}(x - 1)
$$
Check:

Thank you guys for helping me out!
Notes:
*Although, you could find $PT_1$, which is easier since $T_1 = (1,4)$; you would get the same distance regardless because of the Two-Tangent Theorem in geometry.
A: Generally, given $(h,k)$ as the center of the circle, $C$, with radius $r,$ and,  given $P(a,b)$ a point outside $C$; by Joachimsthal the line pair tangent to $C$ and passing through $(h,k)$ is given by $s\cdot s_{11}=s_1^2:$
$$((x-h)^2+(y-k)^2-r^2)((a-h)^2+(b-k)^2-r^2)\\-(x\cdot a+y\cdot b-h(x+a)-k(y+b)+h^2+k^2-r^2)^2\\=-(r-k+b)(r+k-b)(x-a)^2-(r-h+a)(r+h-a)(y-b)^2-2(h-a)(k-b)(x-a)(y-b)\\=-(r-k+b)(r+k-b)\cdot l_1\cdot l_2\\=-(r-h+a)(r+h-a)\cdot l'_1\cdot l'_2\\=0,$$ where, by assumption, $(b-k)^2+(a-h)^2>r^2$ and e.g. solve the quadratic in $t=\frac{x-a}{y-b}$ to get $$l_1: x-a-(y-b)(r\sqrt{(b-k)^2+(a-h)^2-r^2}-hk+ak+bh-ab)
          /((r-k+b)(r+k-b))=0, \\l_2: x-a+(y-b)(r\sqrt{(b-k)^2+(a-h)^2-r^2}+hk-ak-bh+ab)
          /((r-k+b)(r+k-b))=0,$$ or you can solve the quadratic in $t^{-1}=\frac{y-b}{x-a}$ to get $$l'_1: y-b-(x-a)(r\sqrt{(b-k)^2+(a-h)^2-r^2}-h k+a k+b h-a b)/((r-h+a)(r+h-a))=0,\\
l'_2: y-b+(x-a)(r \sqrt{(b-k)^2+(a-h)^2-r^2}+h k-a k-b h+a b)/((r-h+a)(r+h-a))=0,$$ or in some easy cases factor the quadratic directly as in my comment to the question.
As for $P(a,b)$ on $C,$ the equation $s\cdot s_{11}=s_1^2$ becomes $s_1^2=0,$ or the easier fact $s_1=0,$ since then $s_{11}\equiv 0.$
