Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
    
I suggest you that just draw the unit circle and one point (examples: $(3,0), (3,4)$) in the plane, and then you go to sence which point in the unit circle is closest to your point. –  emiliocba Jan 29 '12 at 1:38
add comment

2 Answers 2

up vote 2 down vote accepted

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.)

share|improve this answer
add comment

The closest point to $(x_0, y_0)$ (note the change of notation) on the unit circle will be the one that's on the half-line starting at the origin and passing through $(x_0, y_0)$. This is "obvious" if you draw some pictures. It can also be proven by analytic means. We want to minimize $f(x,y) = (x-x_0)^2 + (y-y_0)^2$, subject to the constraint $g(x,y) = 0$ where $g(x,y) = x^2 + y^2 - 1$. The minimization can be done by Lagrange multipliers: we want to find points where the gradients of $f$ and $g$ are parallel. These are $ (2(x-x_0), 2(y-y_0)) $ and $(2x, 2y)$ respectively; thus $(x-x_0, y-y_0)$ must be a constant multiple of $(x,y)$. So $(x, y)$ is a constant multiple of $(x_0, y_0)$. In particular, for $(x,y)$ to have length $1$ it must be $(x_0, y_0)/\sqrt{x_0^2+y_0^2}$, which is the formula you asked about.

share|improve this answer
    
Thanks for the detailed explanation, I'm sure it'll be helpful for someone but it's unfortunately over my level. –  hattenn Jan 29 '12 at 1:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.