# Find a circle that is tangent to a line and a circle.

I need to find the circle that will be tangent to a line at a given point and a circle. The diagram below hopefully makes it clearer. The known data are:
points P2,P3,P4,P5
Circle C2's radius r
Angle C
The distance from P3 to P2, a

I need to find P1 or b (which makes it easy enough to work out P1). There are actually two solutions to this problem. Circle C1 could also be tangent on the far side of C2 (c=b-r).

As some background info I am using this to find the medial axis of a polygon. By stepping P3 along each line/arc of the polygon I can generate an approximation of the medial axis. I have already worked out the solution for two lines.

The set of points that are equidistant from the circle $C_2$ and the line $P_4P_5$ is a parabola. Translate the line $P_4P_5$ (in the opposite direction than the $P_2$) by the radius $r$ of the circle (i.e. $|P_4'P_4| = r$, $|P_5'P_5| = r$ and $P_4P_5\ \|\ P_4'P_5'$) to get a new line $P_4'P_5'$ and observe that your solution will be equidistant from the line $P_4'P_5'$ and the point $P_2$ (if before the distance was $b$, then now it is $b+r$). Precisely, the $P_2$ will be the focus and $P_4'P_5'$ will be the directrix. To find the point $P_1$ of parabola just construct the perpendicular bisector of $P_3'P_2$, it should intersect $P_3'P_3$ exactly in $P_1$.
$\hspace{50pt}$ $\hspace{50pt}$ 