Calculate circle through a point, with its center on a line
I am trying to make a program in java that calculates the largest circle between two tangential lines through a point that is not on one of the lines.
I have the coordinates of A, B, C and D (the point where the circle goes through), the angle between AB and AC and I already know how to get the bisector. If I could calculate the centers of both circles, I could calculate their radii, so I know which circle is the biggest.
So my question is: How can I get the coordinates of the center of both circles?





Suppose that the given lines make an angle of $2\theta$ at their intersection, $O$, and that the given point, $P$, is such that $\overline{OP}$ makes an angle of $\phi$ with the angle bisector. (We'll assume $-\theta \leq \phi \leq \theta$.) Define $p := |OP|$. Let the circles be tangent to one of the lines at $S$ and $T$, and let $M$ be the midpoint of $\overline{ST}$. Let $P^\prime$ and $M^\prime$ be the reflections of $P$ and $M$ in the bisector. Finally, let $R$ and $R^\prime$ be the feet of perpendiculars from $P$ to the lines, as shown.
Note that $\overleftrightarrow{PP^\prime}$ is the radical axis of the two circles, which necessarily passes through $M$ and $M^\prime$.
Now, by simple trigonometry,
$$|OM| = |OM^\prime| = |ON|\sec\theta = |OP| \cos\phi\sec\theta = p\cos\phi\sec\theta \tag{1}$$ Also, $$\begin{align} |MP\phantom{^\prime}|\phantom{=|PM^\prime|}\; &= |PR\phantom{^\prime}|\sec\theta = |OP|\sin(\theta+\phi)\sec\theta = p\sin(\theta+\phi)\sec\theta \\ |MP^\prime| = |PM^\prime| &= |PR^\prime|\sec\theta = |OP|\sin(\theta-\phi)\sec\theta = p\sin(\theta-\phi)\sec\theta \end{align} \tag{2}$$
By the power of a point theorems, we can express the power of $M$ with respect to the "bigger" circle in two ways: $$|MT|^2 = |MP||MP^\prime| \quad\to\quad |MT|=p\sec\theta\;\sqrt{\sin(\theta+\phi)\sin(\theta-\phi)} \tag{3}$$
We see, then, that tangent point $T$ is the point on the line such that $$|OT|= |OM|+|MT| = p\sec\theta\left(\;\cos\phi + \sqrt{\sin(\theta+\phi)\sin(\theta-\phi)}\;\right) \tag{4}$$
Finally, the perpendicular at $T$ meets the angle bisector at $T_\star$, the center of the bigger circle, and we have
giving the location of the center, and the radius, of the bigger circle. $\square$
Observe that the various trig values are all readily calculated via vector methods.
Write $u$ and $v$ for unit direction vectors of the lines, and $w$ for the unit direction vector of the bisector (ie, $w=(u+v)/|u+v|$). And let $q$ be the vector $\overrightarrow{OP}$ (I want to call it $p$, but that's in use for the length of that vector); if we distribute $p$ across the expressions in $(\star)$, we don't have to bother "unitizing" $q$.
$$p\cos\phi + \sqrt{p\sin(\theta+\phi)\,p\sin(\theta-\phi)} = q\cdot w + \sqrt{|u\times q|\,|q\times v|}$$ $$\sec^2\theta = \frac1{\cos^2\theta} = \frac{1}{(u\cdot w)^2} \qquad \sec\theta\tan\theta = \frac{\sin\theta}{\cos^2\theta} = \frac{|u\times w|}{(u\cdot w)^2}$$