I am working on an open source cad software called FreeCAD. In the sketcher I'm making the snapping feature for hyperbolas curves.
There is an hyperbola, the user put the mouse pointer close to it. So we have the point A, which is close to the hyperbola, but not exactly on it. I need to calculate the coordinates of the point B which is on the hyperbola. (then the point B is used to override the mouse coordinates, such that the hyperbola is exactly under the mouse pointer).
Base::Vector2d A, centerPoint, majorAxis, minorAxis are known.
//This is appantly wrong :
Base::Vector2d vec = A - centerPoint;
double U = atanh(vec.y / minorAxis.Length()) + acosh(vec.x / majorAxis.Length());
//This seems to be OK as it create points on the hyperbola :
B = centerPoint + majorAxis * cosh(U) + minorAxis * sinh(U);
The last line calculates points that are on the hyperbola. So it seems OK, if so the U that is fed into would be wrong.
Do you know how to calculate the point B ? Thanks !

Let the given hyperbola be
$ \dfrac{x^2}{a^2} - \dfrac{y^2}{b^2} = 1 $
And assume that $A = (x_1, y_1) $. We want to find the closest point $B$ on the hyperbola to point $A$. Let $B = (x_2, y_2) $, then we can write two equations for $x_2$ and $y_2$
$\dfrac{x_2^2}{a^2} - \dfrac{y_2^2}{b^2} = 1 \hspace{25pt}(1) $
and
$ ( x_2 - x_1 , y_2 - y_1 ) = \alpha \vec{n} = \alpha ( \dfrac{2 x_2}{a^2} , \dfrac{ -2 y_2}{b^2} ) \hspace{25pt}(2) $
The second equation has an extra variable $\alpha$ that we can eliminate by dividing the $y$ coordinate by the $x$ coordinate. And this gives us
$ \dfrac{ y_2 - y_1 }{ x_2 - x_1 } = - \dfrac{ a^2 y_2 }{ b^2 x_2 } \hspace{25pt} (3)$
Cross multiplying, yields,
$ b^2 (y_2 - y_1) x_2 = - a^2 (x_2 - x_1) y_2 \hspace{25pt}(4)$
Equations $(1)$ and $(4)$ are two quadratic equations in the two unknowns $x_2$ and $y_2$, and can be solved with the help of a math app like Mathematica for example. In the absence of a math app, you can solve numerically, using the multivariate Newton-Raphson root finder algorithm, which is very fast and converges to a solution (from the initial guess of $x_2 = x_1$ and $y_2 = y_1$) with very few iterations (about $4$ or $5$ iterations).
The following figure shows the hyperbola with the initial point off the parabola and the closest point to it on the hyperbola.
In the following, I list the Visual Basic Code to implement the Newton-Raphson root finder for this specific problem.