Mar 26, 2011

Finding a Regression for a Circle

I was recently asked to fit a circle to a bunch of data points much like the one right here. You can see that the points are roughly distributed around in a circle of some kind. The task then is to find the equation of the circle which best fits this data.

The Problem

Fitting an equation to a set of data is not an uncommon problem. There´s a large amount of work done in algorithms for finding the ¨best¨ fit for many different definitions of ¨best¨. The person asking me to solve this problem was under the assumption that the normal method, least squares regression, was the best way of going about solving this problem. Actually, performing least squares regression in this case doesn´t really make any sense since the theory applies to only functions. Circles are not functions and so the theory doesn´t apply.

Despite this fact, there was a desire to stick with something like least square regression. I guess it´s like a brand name that people have come to trust. There was talk of some rather complicated solutions, like breaking up the circle into two branches and performing least squares regression on each half in some way, then averaging the results. Anyway you slice it, you´re coming up with an arbitrary algorithm for finding a fit for the function. So really you might as well come up with a sensible arbitrary algorithm.

The solution for the problem is in fact incredibly easy. If you understand what least squares regression is, then you would never attempt to use it for this kind of problem, or anything really remotely close to it.

I resolved the issue with two very clear ideas that cut the Gordian Knot:

  •  The center of the circle is probably around the center of the points. 
  • The radius of the circle is probably the average distance from the center.
The Simple Solution
This is what the end result is when you plot that circle with the data.  It´s probably pretty close to minimizing the absolute residual of the data against the function. The solution is perfect for what it needed to be used for and took about one line of clear Mathematica to program. Relying on math that you don´t understand often causes you to complicate otherwise simple problems.