Computational Geometry – Fitting Data to a Portion of an Ellipse or Conic Section

computational geometryconic sectionsgeometryregression

Is there a straightforward algorithm for fitting data to an ellipse or other conic section? The data generally only approximately fits a portion of the ellipse. I am looking for something that doesn't involve a complicated iterative search, since this has to run at interactive speeds for data sets on the order of 100s of data points. I can downsample or cluster the data if it goes beyond that.

I found an article: "Least-Squares Fitting of Circles and Ellipses" (Gander et al 1994) and it does seem to address my needs, but it uses a lot of mathematical machinery that I either don't understand or have a library for. I'm sure I can grok it given time, but this isn't something I would like to allocate a week to doing.

Best Answer

It baffles me a bit that people rush to iterative methods, even though in this case there are very straightforward direct methods. A conic section will implicitly be described by a degree $2$ algebraic equation of the form

$$Ax^2+Bxy+Cy^2+Dx+Ey+F=0$$

so if you are given a few points $(x_1,y_1),(x_2,y_2),...$ for each point you get an equation

$$Ax_1^2+Bx_1y_1+Cy_1^2+Dx_1+Ey_1+F=0$$

$$Ax_2^2+Bx_2y_2+Cy_2^2+Dx_2+Ey_2+F=0$$

they are $\textit{linear}$ in the coefficients $A,B,C,...$ of the conic section. So given enough non-degenerate points (technical term "in general poisiton") this homogenous system will have a unique solution. 'Enough' here means five since we will only know $A,B,C,...$ up to a scale factor. If you have more than five points, the system of equations will become overdetermined.

As a joke i once implemented this as a java applet - and it's still up. Maybe this will convince you that this method runs at 'interactive speed' (for five points at least...).

Of course the hard bit then becomes to work with the conic section in the form of the coefficients $A,B,C,...$ - so maybe you have to convert it to the usual parametric form. For this i refer you to for example the ellipse page of math world (equation 15-22). But wikipedia also has more on this.

Related Question