Here is one way to determine the equation of an ellipse given 5 points. (From there, you can work out the parameters that you want.)
Every ellipse has the form $ax^2+bxy+cy^2+dx+ey+f=0$. We'll find $a,b,c,d,e,f$ given 5 points.
Let $(p_1,q_1),\dots,(p_5,q_5)$ be your 5 points. Consider the following linear equations in the variables $a,b,c,d,e,f$: $ax^2+bxy+cy^2+dx+ey+f=0$, $ap_1^2+bp_1q_1+cq_1^2+dp_1+eq_1+f = 0$,...,$ap_5^2+bp_5q_5+cq_5^2+dp_5+eq_5+f = 0$. Note that we're treating $x^2, xy,y^2,x,y,1$ as coefficients in the first equation. Similarly, $p_i^2,p_iq_i, q_i^2, p_i,q_i,1$ are coefficients in the remaining 5 equations.
Since all 5 points lie on the same ellipse, the above linear equations must have common solution. From this, we see that the equation of the ellipse is given by setting the determinant of the matrix of coefficients of the above 6 equations to $0$.
There is a very elegant algorithm to find an encompassing ellipse for points arbitrarily positioned in space via PCA (Principal Component Analysis) approach to find axes of the ellipse.
Suppose you have $n$ points of an ellipse stored in the matrix $E$:
$$
E = \begin{bmatrix}
x_1 & y_1 \\
x_2 & y_2 \\
\vdots & \vdots \\
x_n & y_n
\end{bmatrix}
$$
Let us also suppose that the center of the ellipse is in the origin $(0, 0)$ (if not, just subtract corresponding means from each of the coordinates, i.e. $x_i := x_i-\mu_x, y_i := y_i - \mu_y $).
Then, compute the covariance matrix $C$, in our case we can use the following formula as the resulting matrix will be proportional to the real covariance matrix:
$$
C = E^TE
$$
Finally, find eigenvectors $v_i$ of $C$, in our particular case, $i = 1, 2$. The resulting eigenvectors will have the same direction as the axes of the ellipse you work on. Also, if you normalize a matrix $V = [v_1\;v_2]$, you may see it is actually a rotation matrix. So, if you want to rotate your ellipse in a way that all its points are parallel to coordinate axes, just do the multiplication: $EV$.
In order to find magnitudes of ellipse axes, use the rotated ellipse $EV$: find the biggest values of $x$ and $y$ in the set of points, and these values are the ones you need.
This algorithm will definitely work if the points lie in a 3D space, and it does not require points to lie exactly on the ellipse.
Sources on PCA, eigenvalues, eigenvectors:
- http://www.doc.ic.ac.uk/~dfg/ProbabilisticInference/IDAPILecture15.pdf
- http://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors
Best Answer
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.