Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can someone help me with plugging in the correct values in the equations given in this thread (accepted answer) ->

Calculating Distance of a Point from an Ellipse Border

The result values for x and y do not make any sense at all (for example, they are very very small and not on the ellipse).

var a = 180;
var b = 60;
var t = 68554.6; // -8768.46; // (, see below)
var u = 200;
var v = 100;
var x = (a^2*u)/(a^2-t);
var y = (b^2*v)/(b^2-t);

// (a^2*u^2/(a^2-t)^2) + (b^2*v^2)/(b^2-t)^2 = 1
// --> ((180^2*200^2)/(180^2-t)^2) + ((60^2*100^2)/(60^2-t)^2) = 1 solve for t
share|cite|improve this question
up vote 1 down vote accepted

The formula in the linked answer is correct; however, the issue is that the equation for $t$ may have up to four solutions (it's a polynomial equation of 4th degree). In the specific example here, -8768.46 is the right value of $t$ to use. It gives the point with approximate coordinates (157,29), which is the correct answer:

nearest point

  • When the point $(u,v)$ lies outside of the ellipse, the equation for $t$ has a unique negative root, and this is the one to pick.

  • When the point $(u,v)$ lies inside of the ellipse, all roots will be positive. I'm pretty sure that the smallest root should be used. This worked in all examples I tried. It matches the idea that smaller values of $t$ move the points by the least amount.

Thus, in either case you should pick the smallest value of $t$ that solves the equation.

To make the life of numerical routines easier, you should clear the denominators prior to solving. It makes the equation slightly longer for humans to read, but easier for numerical methods to handle. $$ a^2u^2(b^2-t)^2 +b^2v^2(a^2-t)^2 =(a^2-t)^2 (b^2-t)^2 \tag1$$ Here is how I coded this in Maple:

a:=180; b:=60; u:=200; v:=100;
x0:=(a^2*u)/(a^2-t0); y0:= (b^2*v)/(b^2-t0);

Here fsolve is used instead of solve, because solve may also find complex roots of the polynomial, making min throw an error: complex numbers are not ordered. When used for polynomials, fsolve finds all real roots. If I did not use clear denominators, it would find one real root only, not necessarily the one I want.

Finally, the graphic output part which made the plot shown above.

ellipse:= implicitplot(x^2/a^2+y^2/b^2=1, x=-a..a, y=-b..b, thickness=2): 
points:= pointplot([[x0,y0],[u,v]], symbol=soliddiamond, symbolsize=20): 
display(ellipse, points);
share|cite|improve this answer
Thank you. Also for all the good hints. – user64123 Mar 11 '13 at 19:30

Your Answer


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.