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.

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; // (wolframalpha.com, 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
//
// wolframalpha.com --> ((180^2*200^2)/(180^2-t)^2) + ((60^2*100^2)/(60^2-t)^2) = 1 solve for t
share|improve this question

1 Answer 1

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;
t0:=min(fsolve((a^2*u^2)*(b^2-t)^2+(b^2*v^2)*(a^2-t)^2=(a^2-t)^2*(b^2-t)^2));
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.

with(plots):
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|improve this answer
    
Thank you. Also for all the good hints. –  user64123 Mar 11 '13 at 19:30

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.