Source: Exercise 2.3.18 (p.54) from Convex functions: constructions, characterizations and counterexamples, J.M. Borwein & J.D. Vanderwerff (2010).
Consider $E:=\{(x,y):x^2/a^2+y^2/b^2=1\}$ in standard form. Show that the best approximation is:
$$P_E\,(u,v)=\left(\frac{a^2u}{a^2-t},\frac{b^2v}{b^2-t}\right)$$
where $t$ solves $\frac{a^2u^2}{(a^2-t)^2}+\frac{b^2v^2}{(b^2-t)^2}=1$.
A different solution without having to solve an equation is by rotating the axis back and forth. (more suitable for mathematical programs)
r is the radius of the circle.
O is the origin at [0, 0].
P is any point within the circle [Px, Py].
Q is point at perimeter of the circle
θ is angle from point P to Q positive with x-axis
R is the rotation matrix with R = [cosθ -sinθ; sinθ cosθ]
R' is the inverse rotation matrix
Now rotate such that x-axis is parallel to PQ.
Describe point P and Q as P'and Q' in the new axis orientation.
P' = R'P
because of the parallel alligned the following formula's are true:
Q' = [Q'x, Q'y] = [r * cosφ, r * sinφ],
with φ is angle from O to Q (positive with rotated x-axis)
Q'y = P'y
Substitute φ for P'y gives:
Q'x = r * sin(arccos(P'y/r))
Now all that is left to do is rotate the axis back how it was
Q = RQ'
you can now use pythagoras to get the length PQ
Best Answer
As a preliminary, the equation for an ellipse is $x^2/a^2+y^2/b^2=1$, where the length of the major (long) axis is $2a$.
If we are given the center of the ellipse and a point $P(x,y)$ outside of the ellipse, then we can calculate the distance to the edge as in your diagram by calculating the distance $d$ between point $P$ and the center of the ellipse, then subtracting the distance between the intersection and the center of the ellipse.
By the Pythagorean Theorem, $d=\sqrt{(x-c_x)^2+(y-c_y)^2}$, where $c_x$ and $c_y$ are the $x$ and $y$ coordinates of the center of the ellipse respectively. The slope $m$ of this segment is $\frac{y-c_y}{x-c_x}$, so now we have the equation of a line: $y=mx+b$, where we can find $b$ by substituting our point $P$ or the center of the ellipse $(c_x, c_y)$. We can now substitute this equation into our ellipse equation to find the point on the ellipse that the line intersects, and then use the Pythagorean Theorem again to find this distance, which we'll call $d_1$. Now, the solution is $d-d_1$.