# Finding closest point to implicitly defined curve

I'm facing the following problem: Given an implicit curve given by $f(x,y)=0$ and an initial guess $(x_0,y_0)$ which is hopefully close to the curve, I want to find the point $(x,y)$ on the curve which is closest to $(x_0,y_0)$.

My attempt:

I thought of using FindRoot with the equation repeated twice, i.e.

FindRoot[{f[x,y],f[x,y]},{{x,x0},{y,y0}}]


But this fails spectacularly with $f(x,y)=y-x^2$ and initial points $(0,y_0)$ with $y_0$ large.

Is there a good way to solve this problem?

Thanks!

• NMinimize[{EuclideanDistance[{x, y}, {x0, y0}], f[x, y] == 0}, {x, y}]? – user484 Jul 8 '15 at 6:36
• "closest" - that kind of screams for the use of Minimize[], no? – J. M.'s technical difficulties Jul 8 '15 at 6:37
• Thanks guys. You can close the question now. – user1337 Jul 8 '15 at 6:42
• Better yet, why not answer your own question instead, so you can share what you've learned? – J. M.'s technical difficulties Jul 8 '15 at 7:00
• It might be better to minimize an EuclideanDistance square (a square of the euclidean norm instead of the norm.) – Igor Jul 8 '15 at 11:55

RegionNearest will do this automatically for many cases, including $y-x^2=0$:
RegionNearest[ImplicitRegion[y - x^2 == 0, {x, y}], {0, y0}]