Two approaches exist to the problem of fitting a circle to experimental data.
Our final purpose is to minimize the distance between our set of data points $(x_i,y_i)$ and a generic circle, finding the parameters identifying the best fitting ring. This can be achieved in one of two ways:
\begin{itemize}
\item iterative methods that converge to the minimum of
	\begin{align}
	&\mathcal{F} = \sum_i d_i^2\\
	&d_i = \sqrt{{(x_i-a)}^2 + {(y_i-b)}^2} -R\label{eqn:ortho-dist}
	\end{align}
	where the $d_i$ are the \textbf{orthogonal} (geometric) distances from the experimental points $(x_i,y_i)$ to the hypothetical circle of centre $(a,b)$ and radius $R$;
\item approximate algorithms that replace the distances with some other quantities $f_i$ defined by simple algebraic rules, and minimize the resulting sum
	\begin{align}
	&\mathcal{F'} = \sum_i f_i^2
	\end{align}
\end{itemize}
These two types of fitting algorithms are referred to as \textbf{geometric} and \textbf{algebraic} algorithms, respectively.\\

In the next sections I will briefly discuss the algorithms used for this project. The \textbf{math} algorithm is the simplest mathematical approach to the problem, whereas the \textbf{Taubin} method makes use of some approximation to improve robustness and computational ease. They are both algebraic fitting algorithms. Nevertheless, after the fitting, the circle must be expressed in its geometrical parametrisation in order to extract the data we need, i.e. the radius and the position of the centre.
It will be convenient to start the discussion from the two possible parametrisations, geometric and algebraic, and the relationship between them.

%The simplest model to fit a circle to a set of experimental points $(x_i, y_i)$ by \textbf{orthogonal least squares} minimizes the sum
%\begin{align}
%&\mathcal{F} = \sum_i l_i^2\\
%&l_i = \sqrt{{(x-a)}^2 + {(y-b)}^2} -R
%\end{align}
%where the $l_i$ are the geometric distances from the experimental points to the circle (see \chaptername~\ref{sect:taubin}). CONTROLLARE NOMENCLATURA!


\subsection{Geometrical parametrisation}
The canonical equation of a circle of centre $(a,b)$ and radius $R$ is
\begin{align}
&{(x-a)}^2 + {(y-b)}^2 - R^2 = 0 \label{eqn:canonical}
\end{align}
with the constraint $R>0$.
If we define $r_i (a,b) \equiv \sqrt{{(x_i-a)}^2 + {(y_i-b)}^2}$, then the minimization function becomes
\begin{align}
&\mathcal{F}(a,b,R) = \sum_i {\left( r_i - R \right)}^2
\end{align}
and its minimum with respect to $R$ is attained at $\hat{R} = \frac{1}{n}\sum_i r_i = \bar{r}$, where $n$ is the number of data points. $\hat{R}$ is the best estimator for the radius $R$ in this picture. We can then express $\mathcal{F}$ as a function of the two variables $a$ and $b$ only:
\begin{align}
\mathcal{F}(a,b,\bar{r}) &= \sum_i {\left( r_i - \bar{r} \right)}^2\\
&=\sum_i {\left[ \sqrt{{(x_i-a)}^2 + {(y_i-b)}^2} - \frac{1}{n} \sum_j \sqrt{{(x_j-a)}^2 + {(y_j-b)}^2} \right]}^2\notag
\end{align}

A drawback of this parametrisation is that its robustness with respect to the parameter $R$ is poor when treating experimental points that lie on a very short arc. A small perturbation may result in arbitrarily large values of $R$, even with opposite signs (\figurename~\vref{img:short_arc}).
\begin{figure}
\centering
\includegraphics[width=\textwidth]{Images/pdf/Appendices/short_arc}
\caption{Data points sampled along a short arc. The blue line represents the correct fit. A small inaccuracy may produce a wrong fit (dashed line) with opposite curvature \cite{chernov}.}\label{img:short_arc}
\end{figure}


\subsection{Algebraic parametrisation}\label{app:pratt}
An more elegant approach to the problem was proposed by Pratt in 1987 \cite{Pratt:1987:DLF:37402.37420}. A circle is algebraically described by the equation
\begin{align}
&A\left( x^2 + y^2\right) + Bx + Cy + D = 0\label{eqn:pratt-0}
\end{align}
or, equivalently,
\begin{align}
&{\left( x + \frac{B}{2A} \right)}^2 + {\left( y + \frac{C}{2A} \right)}^2 - \frac{B^2 + C^2 -4AD}{4A^2} = 0 \label{eqn:pratt}
\end{align}

Compared to Eqn.~\ref{eqn:pratt-0}, Eqn.~\ref{eqn:pratt} has the advantage of making two constraints explicit:
\begin{align}
&A \neq 0\\
&B^2 + C^2 - 4AD > 0
\end{align}
An additional constraint may be set, since the circle parameters only need to be determined up to a multiplicative factor. Indeed, setting $A=1$ leads to the usual canonical equation~\ref{eqn:canonical}.\\

Pratt's choice is more convenient: the choice of
\begin{align}
&B^2 + C^2 - 4AD = 1\\
&A > 0
\end{align}
automatically ensures the constraint $B^2 + C^2 - 4AD > 0$. The condition on the sign of $A$ ensures a unique correspondence between a set of parameters $(A, B, C, D)$ and a circle.
With this parametrisation, the distance of a point $(x_i, y_i)$ to the circle is given (after some algebraic manipulations) by
\begin{align}
&l_i = \frac{2 F_i}{1 + \sqrt{1 + 4 A F_i}}
\end{align}
where
\begin{align}
&F_i = A \left(x_i^2 + y_i^2 \right) + Bx_i + Cy_i + D\\
&1 + 4AF_i = \frac{{\left(x_i - a\right)}^2 + {\left(y_i - b\right)}^2}{R^2}
\end{align}
The term $1 + 4AF_i$ inside the square root is always positive, hence $l_i$ is always computable. This formula can be proved to be more numerically robust as compared to the geometric parametrisation \cite{chernov}.\B

\begin{colbox}{F8E0E0}
\textbf{\textit{Conversion formulas between algebraic and geometric parameters}}
\begin{align}
&a = -\frac{B}{2A} \qquad b = -\frac{C}{2A} \qquad R^2 = \frac{B^2 + C^2 - 4AD}{4A^2}\label{eqn:geom-alg-conv-0}\\
&A= \pm \frac{1}{2R} \qquad B = -2Aa \qquad C = -2Ab \qquad D = \frac{B^2 + C^2 -1}{4A}\label{eqn:geom-alg-conv}
\end{align}
\end{colbox}

\T Let us now see the two algorithms \textit{math} and \textit{Taubin} I %have 
mentioned at the beginning of this chapter.