# Closest point on an ellipsoid

I need to know how to get the closest point on the surface of an ellipsoid to another point.

I had an idea, but apparently i was wrong, and oversimplfying.

What i did was squash the ellipsoid and point into local space, so the ellispoid is a unit circle

``````vector3 pointLocalCoord = ( pointOriginal - ellipsoid.origin ) / ellipsoid.radii
``````

Then from there, the closest point should be 1, in the direction of the transformed point from the origin

``````vector3 closestPointOnEllipsoidLocal = norm ( pointLocalCoord )
``````

Then get back into standard space

``````vector3 closestPointOnEllipsoidWorld = closestPointOnEllipsoidLocal * ellipsoid.radius + ellipsoid.origin
``````

But of course, all of this seems not to work, i was curious if any body could point me in the direction of some pre-existing code or such; as some of the articles i've tried reading kinda go a bit out of my scope of knowledge.

Also, if that seems right to you, please do tell. I'm pretty sure its wrong though.

Edit: Sorry for the unresponsiveness with this and my other question. They're different, i was axperimenting with something else

-
That reads correctly to me, if `ellipsoid.radii` is a `Vector3` and `norm` is `Vector3.Normalize` (and `vector3` is `Vector3` for that matter). What is with the non-XNA type and function names? – Andrew Russell May 29 '11 at 14:55
Yeah; and the reason for the non xna stuff, idk... i guess i wasnt gonna originally list it as a xna thing – Larry May 29 '11 at 15:43
-1 This is pretty much the same as your other question. Except that you cant figure out how to implement the answer. IF that is the case update your question and ask for additional information. – AttackingHobo May 29 '11 at 20:42
+1 This is not the same question. I suggest your reconsider your downvote regardless of your consideration for the poster, because it gives people the wrong idea that the answer is trivial. – sam hocevar May 30 '11 at 16:39
If you want to find a general solution, in any dimension, you can check out: mathproblems123.wordpress.com/2013/10/17/… In Matlab you can code it in about 10-20 lines. Using another program shouldn't make things harder. – Beni Bogosel Oct 23 '13 at 20:03