Closest point to a unit circle from a point inside it I'm working on a code at the moment that calculates the closest point to a circle from a point inside it. Let's say we have the point ($x_0, x_1$) to calculate the closest point to the unit circle it first calculates $\rho = \sqrt{x_0^2 + x_1^2}$ and then the closest point to the unit circle is $(x_0 / \rho, x_1 / \rho)$.
I don't know much about geometry and I don't understand how this works. I'd really appreciate it if someone could explain me why and how this works.

The radius that passes through the center and your point $(x_0,y_0)$ also gives the direct path to the closest point on the circle. So the vector $(x_0,y_0)$ needs to be scaled up until its magnitude is $1$. This is accomplished by taking $(x_0,y_0)/\rho$. (And this also applies to points outside the circle.)
