Let the points be $P_1(x_1, y_1)$ and $P_2(x_2, y_2)$, assumed to lie on an ellipse of semiaxes $a$ and $b$ with the $a$ axis making angle $\alpha$ to the $x$ axis.
Following @joriki, we rotate the points $P_i$ by $-\alpha$ into points
$$Q_i(x_i \cos(\alpha) + y_i \sin(\alpha), y_i \cos(\alpha) - x_i \sin(\alpha)).$$
We then rescale them by $(1/a, 1/b)$ to the points
$$R_i(\frac{x_i \cos(\alpha) + y_i \sin(\alpha)}{a}, \frac{y_i \cos(\alpha) - x_i \sin(\alpha)}{b}).$$
These operations convert the ellipse into a unit circle and the points form a chord of that circle. Let us now translate the midpoint of the chord to the origin: this is done by subtracting $(R_1 + R_2)/2$ (shown as $M$ in the figure) from each of $R_i$, giving points
$$S_1 = (R_1 - R_2)/2, \quad S_2 = (R_2 - R_1)/2 = -S_1$$
each of length $c$. Half the length of that chord is
$$c = ||(R_1 - R_2)||/2 = ||S_1|| = ||S_2||,$$
which by assumption lies between $0$ and $1$ inclusive. Set
$$s = \sqrt{1-c^2}.$$
The origin of the circle is found by rotating either of the $S_i$ by 90 degrees (in either direction) and rescaling by $s/c$, giving up to two valid solutions $O_1$ and $O_2$. (Rotation of a point $(u,v)$ by 90 degrees sends it either to $(-v,u)$ or $(v,-u)$.) For example, in the preceding figure it is evident that rotation $R_1$ by -90 degrees around $M$ and scaling it by $s/c$ will make it coincide with the circle's center. Reflecting the center about $M$ (which gives $2M$) produces the other possible solution.
Unwinding all this requires us to do the following to the $O_i$:
- Translate by $(R_1+R_2)/2$,
- Scale by $(a,b)$, and
- Rotate by $\alpha$.
The cases $c \gt 1$, $c = 1$, and $c=0$ have to be treated specially. The first gives no solution, the second a unique solution, and the third infinitely many.
FWIW, here's a Mathematica 7 function. The arguments p1 and p2 are length-2 lists of numbers (i.e., point coordinates) and the other arguments are numbers. It returns a list of the possible centers (or Null if there are infinitely many).
f[\[Alpha]_, a_, b_, p1_, p2_] := Module[
{
r, s, q1, q2, m, t, \[Gamma], u, r1, r2, x, v
},
(* Rotate to align the major axis with the x-axis. *)
r = RotationTransform[-\[Alpha]];
(* Rescale the ellipse to a unit circle. *)
s = ScalingTransform[{1/a, 1/b}];
{q1, q2} = s[r[#]] & /@ {p1, p2};
(* Compute the half-length of the chord. *)
\[Gamma] = Norm[q2 - q1]/2;
(* Take care of special cases. *)
If[\[Gamma] > 1, Return[{}]];
If[\[Gamma] == 0, Return[Null]];
If[\[Gamma] == 1,
Return[{InverseFunction[Composition[s, r]][(q1 + q2)/2]}]];
(* Place the origin between the two points. *)
t = TranslationTransform[-(q1 + q2)/2];
(* This ends the transformations.
The next steps find the centers. *)
(* Rotate the points 90 degrees. *)
u = RotationTransform [\[Pi]/2];
(* Rescale to obtain the possible centers. *)
v = ScalingTransform[{1, 1} Sqrt[1 - \[Gamma]^2]/\[Gamma]];
x = v[u[t[#]]] & /@ {q1, q2};
(* Back-transform the solutions. *)
InverseFunction[Composition[t, s, r]] /@ x
];
I assume that you mean major or minor axis of ellipse is parallel to y-axis.
The equation of an ellipse whose major and minor axes coincide with the Cartesian axes is $$\frac{x^2}{a^2}+\frac{y^2}{b^2}=1$$
For your case you only need to shift the origin to some other point say $(x_0,y_0)$ and equation of ellipse transforms as $$\frac{(x-x_0)^2}{a^2}+\frac{(y-y_0)^2}{b^2}=1$$
Evidently you need four variables to solve it for $x_0,y_0,a,b$.
On a side note for a general ellipse you need to rotate the co-ordinate axes and also shift the origin to some other point.
suppose you rotate by angle $\theta$ anticlockwise and shift origin to $(x_0,y_0)$ then
$x\mapsto((x-x_0)\cos\theta+(y-y_0)\sin\theta)$ and $y\mapsto(-(x-x_0)\sin\theta+(y-y_0)\cos\theta)$ then equation of ellipse transforms as
$$\frac{((x-x_0)\cos\theta+(y-y_0)\sin\theta)^2}{a^2}+\frac{(-(x-x_0)\sin\theta+(y-y_0)\cos\theta)^2}{b^2}=1$$
Above has five variable so you would need five points.
Best Answer
I will assume that $a$ and $b$ are known. What is unknown is the location of the center, and angle of rotation of the axes relative to the $xy$ axes.
The equation of this ellipse is therefore (in matrix-vector format) is
$ (r - C)^T Q (r - C) = 1$
where $ r = \begin{bmatrix} x \\ y \end{bmatrix} $ is a point on the ellipse, and $ C = \begin{bmatrix} C_x \\ C_y \end{bmatrix}$ is the center of the ellipse. Matrix $Q$ is $2 \times 2$, symmetric and positive definite. $Q$ can be written in factored form as
$ Q = R D R^T $
where $ D = \begin{bmatrix} \dfrac{1}{a^2} && 0 \\ 0 && \dfrac{1}{b^2} \end{bmatrix} $
and
$ R = \begin{bmatrix} \cos \theta && - \sin \theta \\ \sin \theta && \cos \theta \end{bmatrix} $
For a set of $ \theta, C_x , C_y $, the equation error of the ellipse equation at the point $r_i = \begin{bmatrix} x_i \\ y_i \end{bmatrix}$ is
$ e_i = (r_i - C)^T R D R^T (r_i - C) - 1 , i = 1, 2, 3$
Using the three points given (without the tangency condition), leads to the overall error function
$ E = \displaystyle \sum_{i=1}^3 e_i^2 = \sum_{i=1}^3 \left( (r_i - C)^T R D R^T (r_i - C) - 1 \right)^2 $
We want to minimize $E$, so taking the partial derivatives of $E$ with respect to the three variables $\theta, C_x, C_y$ gives
$\dfrac{\partial E}{\partial \theta} = 2 \sum_{i=1}^3 \left( (r_i - C)^T R D R^T (r_i - C) - 1 \right) \left( 2 (r_i - C)^T \dfrac{\partial R}{\partial \theta} D R^T (r_i - C) \right) = 0 $
$\dfrac{\partial E}{\partial C_x} = 2 \sum_{i=1}^3 \left( (r_i - C)^T R D R^T (r_i - C) - 1 \right) \left( - 2 e_1^T Q( r_i - C) \right) $
$\dfrac{\partial E}{\partial C_y} = 2 \sum_{i=1}^3 \left( (r_i - C)^T R D R^T (r_i - C) - 1 \right) \left( - 2 e_2^T Q( r_i - C) \right) $
where $e_1 = [1, 0]^T , e_2 = [0, 1]^T $. And
$ \dfrac{\partial R }{\partial \theta} = \begin{bmatrix} - \sin \theta && - \cos \theta \\ \cos \theta && - \sin \theta \end{bmatrix} $
These are three non-linear equations in $\theta, C_x, C_y$ of the form $\mathbf{f} = \mathbf{0}$ where $\mathbf{f}$ is a $3 \times 1$ vector of the right hand sides of the above three equations. One way that I know to solve this vector system for the unknowns is by the Newton-Raphson multivariate method. The method requires the computation of the Jacobian of the vector $\mathbf{f}$ which is defined as follows
$ J = [J_{ij}] $ where $J_{ij} = \dfrac{\partial \mathbf{f}_i }{ \partial \mathbf{x}_j } $
where $\mathbf{x}_1 = \theta , \mathbf{x}_2 = C_x , \mathbf{x}_3 = C_y $.
This computation is very lengthy if done exactly. Instead, it is possible to compute the Jacobian by numerical approximation (i.e. numerical differentiation). It is then trivially simple and easy to compute the Jacobian.
The Newton-Raphson iteration is as follows
$ \mathbf{x}_{k+1} = \mathbf{x}_k - J^{-1}_k \mathbf{f}_k $
The only catch for this method is the need for a "good" initial guess $\mathbf{x}_0$ of the solution. Sometimes, from the nature of the problem, it is possible to obtain such a good initial guess.
I've implemented the above procedure with the points $P_1 = (5, 0), P_2 = (0, 7.9), P_3 = (0, 3.8) $. The initial guess of the parameters that I used was $ \mathbf{x_0}_1 = \theta = - \dfrac{\pi}{6}$, $\mathbf{x_0}_2 = C_x = 4 $, $ \mathbf{x_0}_3 = C_y = 5 $. The Newton-Raphson iteration converged, and the resulting ellipse is shown below. It is quite close to the ellipse in your linked problem (the rolling ellipse problem).
In the second version of the identification procedure, we have only two points, and the angle that normal vector to the ellipse makes with the positive $x$ axis at the first point. In this case we have the equation error for the two points as before, defined as
$ e_i = (r_i - C)^T R D R^T (r_i - C) - 1 , i = 1, 2$
For the third error, we have the normal vector at $r_1$ given by
$ n_1 = R D R^T (r_1 - C) $
And we have the given direction of where the normal vector should be pointing as $n_0$ (assumed a unit vector). The error related to the direction, is defined as the squared difference between $\cos$ the angle between $n_0$ and $n_1$ and $1$. This can be computed using the dot product. So our error function to be minimized is
$ E = e_1^2 + e_2^2 + ( \cos(\phi (n_0, n_1)) - 1 )^2 $
where $\phi(n_0, n_1) = \cos^{-1} \left( \dfrac{n_0 \cdot n_1 }{\| n_1 \|} \right) $
This means that
$ E = e_1^2 + e_2^2 + \left( \dfrac{ n_0^T Q (r_1 - C) }{\| n_1 \|} - 1 \right)^2 $
We can simplify the last term, by redefining the error function to be
$ E = e_1^2 + e_2^2 + ( n_0^T Q (r_1 - C) - \sqrt{(r_1 - C)^T Q^2 (r_1 - C) })^2 $
The derivative of the first two terms of $E$ with respect to $\theta, C_x, C_y$ is the same as before. For the last term $T_3$, we have
$T_3 = K^2 $
with $ K = n_0^T Q (r_1 - C) - \sqrt{(r_1 - C)^T Q^2 (r_1 - C) } $
$ \dfrac{\partial T_3}{\partial \theta} = (2K) \bigg( 2 n_0^T \left(\dfrac{\partial R}{\partial \theta } D R^T + R D \dfrac{\partial R^T }{\partial \theta} \right) (r_1 - C) - \dfrac{ (r_1 - C)^T \dfrac{ \partial R}{\partial \theta} D^2 R^T ( r_1 - C) }{\sqrt{(r_1 - C)^T Q^2 (r_1 - C) }} \bigg)$
and
$\nabla_C T_3 = (2 K) \bigg( -2 Q n_0 + \dfrac{ Q^2 (r_1 - C) }{\sqrt{(r_1 - C)^T Q^2 (r_1 - C) }} \bigg) $
Now we have our non-linear equation which are the derivatives of $E$ with respect to $\theta, C_x, C_y$.
The rest is the same as before. Using the Newton-Raphson method, and with a good initial guess we arrive at the solution. I've implemented the above equations within the Newton-Raphson recursion, and the two points $(5, 0)$ and $(0, 7.8)$ with horizontal tangency at the first point, and I got convergence to the ellipse shown below which is almost identical to the one we obtained before (the one with three points and not tangency information).