# can not find root of the equation $(0,0)$ with semi-major axis a and semi-minor axis $$b$$">

I want find out for each point $$(x,y)$$ in the white region, the nearest point $$(a \cos \theta, b \sin \theta )$$ on the ellipse curve.I tried with the following approach. $$\text {distance} = \sqrt{(x-a \cos \theta)^2+(y-b \sin \theta)^2}$$ I find out the first derivative of the $$F(\theta)=(x-a \cos \theta)^2+(y-b \sin \theta)^2.$$ The equation after first derivative is: $$ax \sec \theta- by \csc \theta=a^2-b^2.$$ How to calculate theta for this equation?

• @Dbchatto67 That's enough editing for now, I think. It's getting quite annoying to focus on writing an answer with the constant notifications coming in. – Arthur Mar 28 '19 at 11:40
• Thanks for editing Arthur! I am new to Stack Exchange and this is the first time I posted any question. – cseju19 Mar 28 '19 at 11:44
• No worries. For next time, have a look at our guide for math formatting. It will make your equations look much better. That being said, it's not an easy equation to solve. Maybe the approach sketched by Pierre below is easier? – Arthur Mar 28 '19 at 11:48

You can get it by solving a constrained optimization problem. You want the point $$(u,v)$$ that minimizes $$f(u,v)=(u-x)^2+(v-y)^2$$ subject to the constraint $$\frac{u^2}{a^2} + \frac{v^2}{b^2} = 1$$. The point $$(x,y)$$ doesn't need to be inside the ellipse.

The Lagrangian is given by $$L(u,v,\lambda) = (u-x)^2+(v-y)^2-\lambda\left(\frac{u^2}{a^2} + \frac{v^2}{b^2}-1\right)$$

Now you just need to compute the critical points of $$L$$ and choose the ones that yield the smallest distance to $$(x,y)$$.

You can solve this by hand but, out of laziness, I give you Wolfram's solution... Two critical points

WARNING: Wolfram is not giving the full set of solutions. After computing $$u,v$$ in terms of $$\lambda$$ from the first two equations of the system $$\nabla L = 0$$ and substituting them in the last equation we get a fourth degree polynomial equation in $$\lambda$$. The solution must be conmputed in an alternative way if this polynomial has four real roots.

$$\left( -\frac{a \sqrt{b^2-y^2}}{b}, \frac{-a^2 b^4 y+a^2 b^2 y^3+a b^3 x y \sqrt{b^2-y^2}+b^6 y-b^4 y^3}{a^4 b^2-a^4 y^2-2 a^2 b^4-a^2 b^2 x^2+2 a^2 b^2 y^2+b^6-b^4 y^2}\right)$$

and

$$\left( \frac{a \sqrt{b^2-y^2}}{b}, \frac{-a^2 b^4 y+a^2 b^2 y^3-a b^3 x y \sqrt{b^2-y^2}+b^6 y-b^4 y^3}{a^4 b^2-a^4 y^2-2 a^2 b^4-a^2 b^2 x^2+2 a^2 b^2 y^2+b^6-b^4 y^2}\right)$$

One will correspond to the minimum distance and the other will correspond to the maximum distance.

This is not relevant to your question, but the Lagrange multipliers are $$\frac{a^2 b^2-a^2 y^2+a b x \sqrt{b^2-y^2}}{b^2-y^2}$$

and

$$\frac{a^2 b^2-a^2 y^2-a b x \sqrt{b^2-y^2}}{b^2-y^2},$$

respectively.

• for critical points(u,v), the coordinate of u is always negative? how? please explain. – cseju19 Mar 28 '19 at 12:29
• Thanks for your quick solution. I am trying to implement this. One more confusion, for critical points(u,v), the coordinate of u is always negative? how? please explain. – cseju19 Mar 28 '19 at 12:41
• There was a typo... I'll correct it. – PierreCarre Mar 28 '19 at 13:03
• Suppose I want to find (u,v) for any point on the major axis (x,0) then (u,v)=(-a,0) and (u,v)=(a,0) from the above equation. But this will not give me shortest distance always. For a point close to center, suppose (3,0), the shortest distance should in the vertical direction, if a>b. Please help me. – cseju19 Mar 28 '19 at 14:29
• I guess Wolfram is dropping some solutions along the way. If you solve it by hand in the simple case $(x,y)=(0,0)$, you will get the following critical points: $(0, \pm b), (\pm a,0)$ and, if $a=b$, every point that satisfies $u^2+v^2=1$ – PierreCarre Mar 28 '19 at 16:39

You have $$axsec(\theta)- bycsc(\theta)= a^2- b^2$$. Let $$z= sec(\theta)$$. Since $$csc(\theta)= \frac{1}{sec(\theta)}$$, the equation becomes $$axz- \frac{by}{z}= a^2- b^2$$. Muliply on both sides to get $$axz^2- by= (a^2- b^2)z$$.
We can write that as $$(ax)z^3+ (b^2- a^2)z- by= 0$$ and solve it using the quadratic formula: $$z= sec(\theta)= \frac{a^2- b^2\pm\sqrt{(b^2- a^2)^2+ 4abxy}}{2ax}$$.

• If you prefix a trigonometric function name with a backslash, LaTeX/MathJax will know it's a symbol and render it with an upright font with appropriate spacing: ax \sec \theta → $ax \sec \theta$ instead of ax sec \theta → $ax sec \theta$. – CiaPan Mar 28 '19 at 12:20
• @user247327: \ csc \theta =1/ \ sin \theta – cseju19 Mar 28 '19 at 12:20