<s>[INST] The closest point from ellipse The closest point of $a$ from the sphere $||x-x_0||= R$ we can give by this formula $$\frac{a-x_0}{||a-x_0||}\cdot R+x_0$$
How we can give such a formula to closest point of $a$ from this ellipse $$\frac{x^2}{A^2}+\frac{y^2}{B^2}=R^2$$
 [/INST] As it was advised, you need to use Lagrange multiplier method. Target function is distance $d$, or, even more convenient $d^2$:
$$
d^2 = \left( x-a_x\right)^2 + \left(y-a_y \right)^2
$$
Restriction is $\varphi(x,y)=\frac{x^2}{A^2}+\frac{y^2}{B^2}-R^2=0$, so
$$
L(x,y) = (x-a_x)^2+(y-a_y)^2-\lambda \left( \frac {x^2}{A^2} + \frac {y^2}{B^2}-R^2\right) \\
\frac {\partial L}{\partial x} = {2(x-a_x)} - \frac {2\lambda x}{A^2} = 0 \\
\frac {\partial L}{\partial y} = {2(y-a_y)} - \frac {2\lambda y}{A^2} = 0 \\
\frac{x^2}{A^2}+\frac{y^2}{B^2}-R^2=0
$$
If you try to solve it, you'll get
$$
x = \frac {a_x A^2}{A^2-\lambda} \\
y = \frac {a_y B^2}{B^2-\lambda}
$$
which you need to substitute into the ellipse equation. In general, that equation is quite nasty, so usually one uses different root finders.
You might be interested in this paper - Distance from a Point to an Ellipse, an Ellipsoid, or a Hyperellipsoid
</s>