I have a circle centered at point $(x_1, y_1)$ and another point at $(x_2, y_2)$. This point, $(x_2, y_2)$ may or may not be within the radius ($r$) of the circle. I wanted to create a line going from the center of the circle $(x_1, y_1)$ to the point $(x_2, y_2)$. I have been using the quadratic formula to determine the intersection between this line and the radius of the circle. In my application, the point $(x_2, y_2)$ was always outside of the circle, so it made sense to always have a single intersection point along the radius of the circle. However, when $(x_2, y_2)$ is within the circle, I was not able to determine a point of intersection.
Is there a simple way to determine the closest point from $(x_2, y_2)$ to the circle's radius? If the line from $(x_1, y_1)$ were to extend forever, it would be the intersecting point of this extended line the circle's radius.
I am using the quadratic equation, but I am having troubles figuring out the intersection, without artificially extending the line. Is it also possible to determine the closest point from $(x_2, y_2)$ to the circle's radius if you don't know whether it is in or out of the radius? If wondering, I am using this in a coding environment.
I added my Inkscape drawing (editing with Paint it to show my application to match the question; please ignore the missing line and resulting gap from the circle).
Thank you.