Is it always possible to draw an ellipse given any two points and the center?

2.3k Views Asked by At

I have 2 points and I want to draw an ellipse that passes through those points.
I also have the center of the ellipse.

My question is: is it always possible to draw such an ellipse?

$\frac{(x-c_x)^2}{a^2} + \frac{(y-c_y)^2}{b^2} = 1$

When trying to automatically render ellipses for information visualization, I tried calculating the radiuses $a$ and $b$ by solving the two-equation system. However, sometimes $a^2$ or $b^2$ would be negative and, therefore, $a$ or $b$ would return me $NaN$.

Edit: A test case where this is failing is with:
$P_1 = (610, 320)$
$P_2 = (596, 887)$
$C = (289, 648)$

Edit2: I'm sorry, I made it seem like a completly theoretical question but in fact I need to overcome this limitation. The suggestion in the comments involves a "tilted ellipse", but how exactly can I get its parameters with two points and the center?

3

There are 3 best solutions below

0
On BEST ANSWER

As other answers have pointed out, it’s not always possible to draw an axis-aligned ellipse with center $C$ that passes through the points $P_1$ and $P_2$. If you relax the axis alignment requirement, then if the three points $C$, $P_1$ and $P_2$ are not colinear it’s always possible to draw an ellipse; it will in general not be axis-aligned, however. In fact, there is an infinite number of such ellipses.

As you’ve noted, one possibility is to take the line through $C$ and the farther of the two other points from it as the major axis. The parameters of the ellipse can be computed fairly easily by applying a change of coordinates that makes the major axis the $x$-axis and places $C$ at the origin.

Another possibility is to take $CP_1$ and $CP_2$ as conjugate half-diameters of the ellipse, which leads to the parameterization $$C+(P_1-C)\cos t+(P_2-C)\sin t.$$ If you need an implicit Cartesian equation of this ellipse, you can (somewhat painstakingly) eliminate $t$. The parameters of the ellipse can then be extracted from the general conic equation using standard formulas. Alternatively, we can use the fact that at the vertices, the radius and tangent vectors are orthogonal. This condition leads to the equation
$$2(P_1-C)\cdot(P_2-C)\cos{2t} = \left(\lVert P_1-C\rVert^2 - \lVert P_2-C\rVert^2\right) \sin{2t}.$$ Setting $s$ and $c$ to the coefficients of $\cos{2t}$ and $\sin{2t}$, respectively, we have $$\cos{2t} = {c\over\sqrt{c^2+s^2}}, \sin{2t} = {s\over\sqrt{c^2+s^2}},$$ and you can use standard half-angle formulas to compute $\cos t$ and $\sin t$ and then find the ellipse’s semiaxis vectors.

For your example, this produces the following ellipse:

ellipse

Its semiaxis lengths work out to be approximately $465.651$ and $381.004$, and the major axis has approximate direction $(0.853,-0.522)$, which corresponds to an angle of $-31.48°$ from the $x$-axis.

1
On

$b^2(x_1-c)^2+a^2(y_1-d)^2=(ab)^2$ $b^2(x_2-c)^2+a^2(y_2-d)^2=(ab)^2$

The difference $$b^2(x_1-x_2)(x_1+x_2-2c)+a^2(y_1-y_2)(y_1+y_2-2d)=0$$ note that $x_1,x_2,y_1,y_2,c,d$ are given so we find a relation between $a^2,b^2$ we use that in the first or second equation to find the $a,b$ values we take positive values. If $a^2,b^2$ are negative then there is no solution!

Let translate the ellipse by make the center $(0,0)$ in your example $C(0,0)$ $P_1(321,-328)$ $P_2(307,239)$ Now $a$ is the largest horizontal distance possible it should be bigger than $321$ and $b$ vertical radius should be bigger than $328$. What I was thinking is it is not always possible to draw an ellipse knowing the center and two other points.

Edited:As @Oscar Lanzi pointed out if $a^2,b^2$ are negative then we have a hyperbola

4
On

Let's translate the coordinates so that the centre is at the origin. The two given points are then $Q_1 = P_1-C = (321, -328)$ and $Q_1 = P_2-C = (307, 239)$.

Since the centred ellipse will be symmetric w.r.t. the axes, we can ignore the minus sign and use $Q_1' = (321, 328)$ instead, as that will also need to be on the ellipse. The two points are now both in the first quadrant.

If you connect any two points in the first quadrant of an origin-centred axis-aligned ellipse, you will get a line with a negative slope. Or put another way, one of the points has the largest x-coordinate, and the other then must have the largest y-coordinate. Conversely, if you have any two points with positive coordinates, one with a largest x-coordinate and the other with the largest y-coordinate, then there is an origin-centred axis-aligned ellipse that goes through them.

This is not the case here with the two points $(321, 328)$ and $(307, 239)$. The first point has both coordinates larger than the other. So no origin-centred axis-aligned ellipse is possible through those points.