TITLE: Distance From A Point To A General Ellipse
QUESTION [7 upvotes]: I have the equation of an ellipse, with known coefficients, as follows:
$ A x^{2} + B x y + C y^{2} + D x + E y + F = 0$, where $ B^{2} - 4 A C < 0 $
This ellipse is perfectly general:  While it is an ellipse, its center may not be at the origin and it may be rotated in the XY plane.
I also have a point in the XY plane, which may be inside, outside, or on the ellipse. 
Is there a closed form solution for the distance between the point, and the nearest point to it on the ellipse?
(Please note that I do not believe this is a duplicate.  There are several similar questions, but always with simplifying assumptions restricting the position and/or orientation of the ellipse, either in the question itself or in the answers.)

REPLY [3 votes]: Let's assume that we have a variable point on ellipse ($x,y$)
Distance between  ($x,y$)  and other point ($x_1,y_1$) is called as $d$
If you  wish to find minimum of the distance , you need to apply derivatives  for $d$ over $x$
$$d=\sqrt{(y-y_1)^2+(x-x_1)^2}$$
$$d'=\dfrac{(y-y_1)y'+(x-x_1)}{\sqrt{(y-y_1)^2+(x-x_1)^2}}$$
Minumum distance is required , so we need $d'=0$.
 we get $y'=-\dfrac{(x-x_1)}{y-y_1} \tag{1}$
$y'$ can be found from ellipse equation easily:
$$ A x^{2} + B x y + C y^{2} + D x + E y + F = 0$$
Let's apply derivatives over x to get $y'$.
$$ 2A x + B  y+B x y'  + 2C y y' + D  + E y' = 0$$ 
$$y'=-\dfrac{2A x+By+D}{Bx+2Cy+E}  \tag{2}$$
If we accept that the minimum point on ellipse , the point  is $P(x_2,y_2)$
And we need to replace $x,y $ to $x_2,y_2$.
y' terms must be same with Equation 1 and 2
$$\dfrac{2A x_2+By_2+D}{Bx_2+2Cy_2+E}=\dfrac{x_2-x_1}{y_2-y_1}$$
And you also have ellipse equation
 $$ A x_{2}^{2} + B x_2 y_2 + C y_2^{2} + D x_2 + E y_2 + F = 0$$
Now you need to solve these two equations to find $x_2$ and $y_2$.
$x_2$ or $y_2$ will be a quartic equation.You will have four solutions. One pair of them will be minimum distance. If you need the solution of the quartic in closed form will be expressed via quite complex expressions. You can find exact solution of quartic in here. (https://en.m.wdikipedia.org/wiki/Quartic_function)