Fit an ellipse with constraints

1.5k Views Asked by At

I'd like to fit an ellipse with the equation of

$ x^2 + ay^2 + bx + c =0 $

This is basically the equation of an ellipse with no tilt and with its center on the horizontal axis.

I have some examples of how to fix curve on the general for of an ellipse, but I do not know how to apply the mentioned constraints. Can anyone kindly guid me on this or refer me to a page or document?

Thanks in advance.

2

There are 2 best solutions below

3
On

If you have some $(x,y)$ points (at least $3$) and you want an exact fit, you have to solve the system of equations in three unknowns $a$, $b$, $c$ that you get by plugging in these values for $x$ and $y$. If you have more points than equations and the fit is not necessarily exact, you might do linear least squares.

5
On

I may be totally wrong; so forgive me if this is the case.

I have the feeling that you want to use a general software for fitting conics and that you want to restrict it to your case (from here comes your constraint).

As Robert Israel answered, why don't you just use the basic definition of the least square fit and minimize with respect to parameters $a,b,c$ the objective function $$\Phi=\sum_{i=1}^n (x_i^2 + ay_i^2 + bx_i + c)^2$$ Writing the partials and setting them to zero leads to a simple set of three linear equations in $a,b,c$.

Added later

As said in comments, I used your data points and the problem solves nicely.

If you want to force your sofware to generate an ellipse, I give you a trick : you have $N$ data points of coordinates $(x_i,y_i)$. So, add to your data set $N$ extra points with coordinates $$x_{N+i}=x_i$$ $$y_{N+i}=-y_i$$ I bet that the difficulties you face are related to the fact that all the $y$'s you gave me are positive.