Calculate a point on an parabola from a nearby point. For an open source cad software called FreeCAD. In 2d editor I'm making the snapping feature for parabolas curves.
There is an parabola, the user put the mouse pointer close to it. So we have the point A, which is close to the parabola, but not exactly on it. I need to calculate the coordinates of the point B which is on the parabola close to A. (then the point B is used to override the mouse coordinates, such that the parabolais exactly under the mouse pointer).

Do you know how to calculate the point B ?
Thanks !
PS: Here is the same question but for hyperbola: Calculate a point on an hyperbola from a nearby point.
 A: Let us consider the case of the reference parabola with equations :
$$x=t, \ \ y=at^2 \ \ \iff \ \ y=ax^2\tag{1}$$

Fig. 1 : Different points $A$ (red circles) and their "projections" $H$ (blue circles) onto the parabola.
I propose to replace the point $A$ "clicked" by the user by point $H$ on the parabola as indicated on the figure, that can be described as being "almost" the foot of the perpendicular line drawn from $A$ to line $BC$ in right triangle $ABC$ ; in fact, the real point $H$ is the (slightly different) point obtained as the intersection of this perpendicular line and the parabola.
The different steps are as follows :
Let $A(u,v)$ the point clicked by the user.

*

*$B$ has coordinates $(u,f(u))$.


*$C$ has coordinates $(\sqrt{v/a},v)$ (check that (1)) is verified).
As the slope of line $BC$ is $s=\frac{v-f(u)}{\sqrt{v/a}-u}$, the slope of the orthogonal line to line $BC$ passing through $A$ is $-\frac{1}{s}$. The equation of this line is therefore :
$$y-v=\underbrace{-\frac{1}{s}}_{slope}(x-u)\tag{2}$$
The determination of the abscissas of the intersection point of this line with the parabola is obtained by plugging (1) into (2).
The result is a quadratic equation whose (well chosen !) solution provides the abscissa of point $H$.
This has to be slightly modified for the case of negative abscissas (see Matlab program below) by detecting the signs of the "protagonists".
The general case is obtained by using a rotation-translation bringing the standard axes we have used above onto the "real axes".
 a=0.5;t=-2:0.01:2;
 f=@(t)(a*t.^2); % function f(t)=at^2
 plot(t,f(t)); % parabola
 for i=1:20
    u=3*rand-1.5;v=f(u)+0.6*rand-0.3; % random points A
    w=sign(u)*sqrt(v/a); % absc. of C
    k=(u-w)/(v-f(u)); % slope of AH
    d=k^2-4*a*(k*u-v); % discriminant of quadratic
    x=(k+sign(u)*sqrt(d))/(2*a); % root of quadratic = absc. of H
    plot([u,x],[v,f(x)]); % line segment AH
 end;

