# Curve fitting a circle (as in linear regression)

I have points in a plane and I want to fit a circle to these points. Is there a 'regression-type' to these points, somewhat akin to linear regression, with a corresponding $R^2$ value? Your insights please.

• Dedicated monograph by Nikolai Chernov crcpress.com/… Nov 29 '17 at 9:37
• See solutions at gis.stackexchange.com/questions/40660 and (to fit multiple circles simultaneously) stats.stackexchange.com/questions/8213.
– whuber
Nov 29 '17 at 16:57
• @Nick Very nice reference. (Grossly overpriced, though, IMHO--at half the price I might consider it and at a third the price I would buy it as a matter of course for my personal library.)
– whuber
Nov 29 '17 at 17:00
• I presume that the standard problem is finding a centre and a radius. If the problem was to find a radius given a known centre, I imagine you'd just use any attractive method to summarize distances to known centre. Nov 29 '17 at 18:24

Love the question! I think I would go about it like this: If you have tuples of x- and y-coordinates in a data set as $D = \{(x_1,y_1), (x_2,y_2), \dots, (x_n,y_n) \}$ and your hypothesis would be that there exist $h,k$ and $r$ s.t. \begin{align} (x_i-h)^2 + (y_i-k)^2 = r^2 + \varepsilon_i , \end{align} with $\varepsilon_i$ being some error centered at zero and with finite variance (i.e., with conditions that make regressions feasible).
Rewriting the above gives you \begin{align} x_i^2 - 2x_ih + h^2 + y_i^2 - 2y_ik + k^2 = r^2 + \varepsilon_i, \end{align} and you want to get estimates $\hat{h}, \hat{k}, \hat{r}$. So you define $\alpha = r^2 - k^2 - h^2$ and rewrite the above as \begin{align} (x_i^2 + y_i^2) = \alpha + 2x_ih + 2y_ik + \varepsilon_i, \end{align} where the left hand side gives you the independent variable of your regression equation,and the left hand side gives you three regressors: the constant/intercept ( = $\alpha$) as well as $2\cdot x_i$ and $2\cdot y_i$ with corresponding coefficients $h$ and $k$. Now finally, note that because $r>0$ by definition of the radius, we can estimate $\hat{k}$ and $\hat{h}$ to recover $r$ from $\hat{\alpha}$ as $\hat{r} = \sqrt{\hat{\alpha} - \hat{k}^2 -\hat{h}^2}$ so long as it holds that $\hat{\alpha} > \hat{k}^2 + \hat{h}^2$.
If the requirement that $\hat{\alpha} > \hat{k}^2 + \hat{h}^2$ is violated in practice (note: If your error term $\varepsilon_i$ has mean zero and finite variance, then the estimates $\hat{\alpha}, \hat{k}$, and $\hat{h}$ are all consistent, implying that $\mathbb{P}(\hat{\alpha} > \hat{k}^2 + \hat{h}^2) \to 0$ as $n \to \infty$, suggesting that a violation of that requirement might be due to insufficient sample size or your data not being arranged in a circle), I would start looking into constrained linear regressions that are intimately linked with linear programming techniques, see for instance here: How do I fit a constrained regression in R so that coefficients total = 1?
• This looks like a good general approach, but modeling the squared distance seems unnatural. Much more often, it is $(x,y)$ that is measured with some zero-mean error, not its distance to the circle's origin. This is a significant but potentially important complication, especially when the measurement error is sizable enough to be of concern.