I'm reading through the source code of RVO2, and I just can't wrap my head around one line.
The task is to find the lines tangent to a circle (centered at $(a, b)$ with radius $r$) that go through the origin point. Using the Pythagorean Theorem, we can say that $l := \sqrt{a^2 + b^2 - r^2}$ is the length of the line segment from the origin point to the contact point of the circle with the lines.
Then, the authors compute the tangent lines' slopes as: $$ m_1 = \frac{ar + bl}{al - br} \,\,\,\,\,\,\,\,m_2 = \frac{-ar+bl}{al+br} $$
I've played around with Geogebra and, given that the circle doesn't contain the origin point, this seems to generally be true, but I'm really struggling to prove this and I can't find any proofs online either. Does anyone have an idea for a proof?
Let $(a,b)$ be the center of the circle. From the angles marked, the slope of CD will be $\tan (\alpha + \beta)$.
Join AD. You’ll notice that $$\tan \beta =\frac{AD}{DC}=\frac rl;\\tan \alpha =\frac{b-0}{a-0}=\frac ba.$$
Th slope of the tangent is $$\displaystyle\tan(\alpha+\beta)=\frac{\tan\alpha+\tan\beta}{1-\tan\alpha\tan\beta}=\frac{\frac rl+\frac ba}{1-\frac rl \cdot \frac ba}=\frac {ar+bl}{al-br}.$$
The other slope should now be doable. Hint: Mark $\angle ACB$ as $\lambda$ and use the $\tan (A-B)$ formula.