The very simple ring fitting algorithm developed by K\r{a}sa and the later, more stable and ``elegant'' Pratt modification are throughly described in \cite{Pratt:1987:DLF:37402.37420,journals/pami/Taubin91,chernov} and we will not discuss them here in detail.\\

Another method for algebraic circle fitting was proposed in 1991 by Gabriel Taubin \cite{journals/pami/Taubin91}.
His method is very similar to the Pratt algorithm both in design and performance, but:
\begin{itemize}
\item it can be generalized to ellipses and other algebraic curves;
\item it features smaller bias and higher statistical accuracy;
\item it requires simpler computations, and therefore it is less ``expensive''.
\end{itemize}

The Taubin algorithm is based on the minimization of the function
\begin{align}
&\mathcal{F}_2 = \dfrac{\sum_i {\left[ {\left(x_i - a\right)}^2 + {\left(y_i - b\right)}^2 -R^2 \right]}^2}{\sum_i \left[ {\left(x_i - a\right)}^2 + {\left(y_i - b\right)}^2 \right]}
\end{align}
as a result of the development of few simple algebraic ideas.\\

%Let
%\begin{align}
%&f_i \equiv {\left(x_i -a \right)}^2 + {\left(y_i -b\right)}^2 -R^2 \label{eqn:f_i}
%\end{align}
%be the algebraic distance from the experimental point $\left( x_i,y_i \right)$ to the circle ${\left(x_i -a \right)}^2 + {\left(y_i -b\right)}^2 +R^2 = 0$.
%The simplest algebraic model for circle fitting to a set of points would minimize the sum \cite{chernov}
%\begin{align}
%&\mathcal{F}_1 = \sum_i f_i^2 \label{eqn:kasa_0}
%\end{align}
%This is called the K\r{a}sa algorithm.
Take the so-called algebraic distances $f_i$ as defined in Eqn.~\ref{eqn:f_i}.
Now consider the expansion
\begin{align}
&r_i \equiv \sqrt{{\left(x_i -a \right)}^2 + {\left(y_i -b\right)}^2}\\
&f_i = (r_i - R) (r_i + R )
\end{align}
The K\r{a}sa and ``math'' methods effectively minimize the sum $\mathcal{F}_1 = \sum_i d_i^2 D_i^2$, where we can identify the two factors as the distances from the $i-$th point to the \textit{nearest} point of the circle ($d_i = r_i - R$, as defined in Eqn.~\ref{eqn:ortho-dist}) and to the \textit{farthest} point on the circle ($D_i = r_i + R$).
Unfortunately, this is the reason why the K\r{a}sa method, and therefore also the ``math'' mathod, are heavily biased towards smaller circles, underestimating the radius when the data points lie on a short arc. By minimizing the averaged product of $d_i^2$ and  $D_i^2$ one may only find the best trade-off between the two distances: a smaller circle would yeld smaller $D_i^2$, minimizing $\mathcal{F}_1$ regardless of the larger $d_i^2$ \cite{chernov}. The solution found by Pratt \cite{Pratt:1987:DLF:37402.37420} solves the statistical bias introduced by K\r{a}sa, but involves matrix algebra and therefore it is less numerically stable.\\

Now observe that, if the points are close to the circle,
\begin{align}
&\left.\begin{array}{l}
D_i = d_i + 2 R\\
|d_i| \ll R
\end{array}\right\}
\Longrightarrow \mathcal{F}_1 \approx 4 R^2 \sum_i d_i^2 \label{eqn:kasa_1}
\end{align}
A natural assumption $| d_i | \ll R$ yields:
\begin{align}
&R^2 \approx {\left(R + d_i\right)}^2 = {\left(x_i -a \right)}^2 + {\left(y_i -b\right)}^2 = r_i^2
\end{align}
Positive and negative fluctuations will tend to cancel out if we average over the whole sample:
\begin{align}
&R^2 \approx \frac{1}{n} \sum_i \left[ {\left(x_i - a\right)}^2 + {\left(y_i - b\right)}^2 \right] = \frac{1}{n} \sum_i r_i^2
\end{align}
Eqn.~\ref{eqn:kasa_1} now factorizes into
\begin{align}
&\mathcal{F}_1 \approx \left( \frac{4}{n} \sum_i r_i^2 \right) \times \left( \sum_i d_i^2 \right) \equiv \mathcal{F}_r \times \mathcal{F}_d
%&\mathcal{F}_1 \approx \frac{4}{n} \left\{ \sum_i \left[ {\left(x_i - a\right)}^2 + {\left(y_i - b\right)}^2 \right] \right\} \left\{ \sum_i d_i^2 \right\}
\end{align}
We ultimately wish to minimize the second factor ($\mathcal{F}_d$). Comparing Eqns.~\ref{eqn:f_i}--\ref{eqn:kasa_0} and the expression \ref{eqn:kasa_1} for $\mathcal{F}_1$, we can define a new minimization function $ \mathcal{F}_2 \equiv \mathcal{F}_1 / \mathcal{F}_r $% the form \ref{eqn:taubin_0}
\begin{align}
\mathcal{F}_2 &= \dfrac{\sum_i {\left[ {\left(x_i - a\right)}^2 + {\left(y_i - b\right)}^2 -R^2 \right]}^2}{4/n \,\sum_i \left[ {\left(x_i - a\right)}^2 + {\left(y_i - b\right)}^2 \right]}\notag\\
&= \dfrac{\sum_i {\left(z_i - 2ax_i -2by_i +a^2 +b^2 -R^2 \right)}^2}{4/n \,\sum_i \left( z_i - 2ax_i -2by_i +a^2 +b^2 \right)} \label{eqn:taubin_0}
\end{align}
by minimizing which we can approximately achieve our goal. Above, we denoted $z_i \equiv x_i^2 + y_i^2$ for brevity.\\

Switching to the algebraic parameters $(A,B,C,D)$ defined in Eqn.~\ref{eqn:geom-alg-conv}, we get
\begin{align}
&\mathcal{F}_2 = n \, \frac{\sum_i {\left( A z_i + B x_i + C y_i + D \right)}^2}{\sum_i \left( 4 A^2 z_i + 4 AB x_i + 4 AC y_i + B^2 + C^2  \right)}\label{eqn:taubin_1}
\end{align}
The minimization of \ref{eqn:taubin_1} is equivalent to minimizing
\begin{align}
&\mathcal{F}_3 \equiv \sum_i {\left( A z_i + B x_i + C y_i + D \right)}^2\label{eqn:taubin_2}
\end{align}
with respect to the parameters $(A,B,C,D)$, with the constraint 
\begin{align}
&4 A^2 z_i + 4 AB x_i + 4 AC y_i + B^2 + C^2 = 1\label{eqn:taubin_3}
\end{align}
as discussed in Section~\ref{app:pratt}.\\

Finally, in \textbf{matrix form}, Taubin's algorithm requires the minimization of
\begin{align}
&\mathcal{F}_3 (\mathbf{A}) = \mathbf{A}^T \left( \mathbf{X}^T \mathbf{X} \right) \mathbf{A}
\end{align}
with the constraint $\mathbf{A}^T \mathbf{T} \mathbf{A} = 1$, where:
\begin{align}
&\mathbf{A} = \left[ \begin{array}{c}
A\\B\\C\\D
\end{array}\right] \qquad
\mathbf{T} = \left[ \begin{array}{cccc}
4\overline{z} & 2 \overline{x} & 2\overline{y} & 0\\
2\overline{x} & 1 & 0 & 0\\
2\overline{y} & 0 & 1 & 0\\
0 & 0 & 0 & 0
\end{array}\right]\\
&\mathbf{X} = \left[ \begin{array}{cccc}
z_1 & x_1 & y_1 & 1\\
\vdots & \vdots & \vdots & \vdots\\
z_n & x_n & y_n & 1
\end{array}\right]
\end{align}
where $\bar{z} = \frac{1}{n}\sum_i z_i$, and $\mathbf{X}$ is called the \textit{extended data matrix}.


\subsection{Implementation of the Taubin algorithm}
Eqns.~\ref{eqn:taubin_1}, \ref{eqn:taubin_2} and \ref{eqn:taubin_3} can be much simplified, reducing the problem to that of finding the roots of a third order polynomial \cite{chernov}.\\

$\mathcal{F}_2$ is a second order polynomial in $D$, and therefore admits a unique minimum in $D = -A \overline{z} - B\overline{x} -C \overline{y}$. Substituting in Eqn.~\ref{eqn:taubin_3}, we get the equations of the two constraints to the minimization of $\mathcal{F}_2$ (Eqn.~\ref{eqn:taubin_2}):
\begin{align}
&D = -A \overline{z} - B\overline{x} -C \overline{y}\\
&B^2 + C^2 - 4AD = 1
\end{align}

Now perform the change of coordinates described in Eqn.~\ref{eqn:math_change_coord}, and let $w_i \equiv u_i^2 + v_i^2$.
The above contraints become
\begin{align}
&D = -A \overline{w}\\
&A_0^2 + B^2 + C^2 = 1
\end{align}
having defined $A_0^2 \equiv 4\overline{w}A^2$, and the function to minimize can be written as
\begin{align}
&\mathcal{F}_5 = \sum_i {\left( \frac{w_i - \overline{w}}{2\sqrt{\overline{w}}} A_0 + B u_i + C v_i \right)}^2\label{eqn:taubin_4}
\end{align}
In matrix form, this corresponds to
\begin{align}
&\left\{ \begin{array}{l}
\mathcal{F}_5 ( \mathbf{A_0} ) = \mathbf{A_0}^T \left( \mathbf{U}^T \mathbf{U} \right) \mathbf{A_0}\\
\mathbf{A_0}^T \mathbf{A_0} = 1
\end{array} \right.
\end{align}
where
\begin{align}
& \mathbf{A_0} = \left[ \begin{array}{c}
A_0\\
B\\
C
\end{array} \right]
\qquad\quad \mathbf{U} = \left[ \begin{array}{ccc}
(w_1 - \overline{w})/2\sqrt{\overline{w}} & u_1 & v_1\\
\vdots & \vdots & \vdots\\
(w_n - \overline{w})/2\sqrt{\overline{w}} & u_n & v_n
\end{array} \right]
\end{align}
are the modified vector of parameters and data matrix.\\

The minimization can be performed using a Lagrange multiplier $\eta$:
\begin{align}
&\mathcal{G}(\mathbf{A_0},\eta) \equiv \mathbf{A_0}^T \left( \mathbf{U}^T \mathbf{U} \right) \mathbf{A_0} - \eta \left( \mathbf{A_0}^T \mathbf{A_0} - 1 \right)\\
&\frac{\partial \mathcal{G} }{\partial \mathbf{A_0}} = \left( \mathbf{U}^T \mathbf{U} \right) \mathbf{A_0} - \eta\, \mathbf{A_0} \equiv 0\\
&\left( \mathbf{U}^T \mathbf{U} \right) \mathbf{A_0} = \eta \,\mathbf{A_0}\label{eqn:taubin_5}
\end{align}
Our algorithm reduces to the \textbf{eigenvalue problem} of Eqn.~\ref{eqn:taubin_5}. Observe that
\begin{align}
&\mathcal{F}_5 ( \mathbf{A_0} ) = \mathbf{A_0}^T \left( \mathbf{U}^T \mathbf{U} \right) \mathbf{A_0} = \eta\, \mathbf{A_0}^T \mathbf{A_0} = \eta
\end{align}
The minimum of Eqn.~\ref{eqn:taubin_4} is therefore attained by the eigenvector $\mathbf{A_0}'$ of $\mathbf{U}^T \mathbf{U}$ corresponding to its smallest eigenvalue $\eta'$ \cite{chernov}. $\mathbf{U}^T \mathbf{U}$ is symmetric and positive-definite, therefore its eigenvalues are all real and positive. The characteristic equation of this problem
\begin{align}
&\det \left( \eta \mathbf{I} - \mathbf{U}^T \mathbf{U} \right) = 0
\end{align}
can be written as a third order polynomial in $\eta$:
\begin{align}
&p(\eta) = c_0 + c_1 \eta + c_2 \eta^2 + c_3 \eta^3 = 0
\end{align}
with
\begin{align}
c_0 &= \overline{uw}\, (\overline{uw}\, \overline{v^2} - \overline{vw}\, \overline{uv} )\notag\\
	&+ \overline{vw}\, ( \overline{vw}\, \overline{x^2} - \overline{uw}\, \overline{uv} ) - \Var\, z\; \Cov (x,y)\\
c_1 &= \left[ \Var\, z + 4 \Cov(x,y) \right] \overline{w} - \overline{uw}^2 - \overline{vw}^2\\
c_2 &= -3 \overline{w}^2 - \overline{w^2}\\
c_3 &= 4 \overline{w}\\
\Var\, z &= \overline{w^2} - \overline{w}^2\\
\Cov (x,y) &= \overline{u^2}\, \overline{v^2} - \overline{uv}^2
\end{align}
Observing the coefficients and the form of $p(\eta)$, we find that:
\begin{itemize}
	\item $p(\eta=0) = \det \left(- \mathbf{U}^T \mathbf{U} \right) < 0$ (the matrix results singular only in the case that all the experimental points lie exactly on a circle).
	\item $p''(\eta = 0) < 0$ , and the only root of $p''(\eta)=0$ is $\eta_2 = -2c_2 / 6c_3 >0$. Hence, $p''(\eta) <0$ in the interval between $0$ and its lowest root.
\end{itemize}
The latter point implies that the function $p(\eta)$ is convex upwards. Therefore a \textbf{Newton} procedure supplied with the initial guess $\eta=0$ is bound to converge to the smallest positive root of $p(\eta)$ \cite{chernov}.\\

Once the eigenvalue $\eta'$ is computed, the circle parameters can be found simply solving the equation for the corresponding eigenvector $\mathbf{A_0'}$:
\begin{align}
&\left(\mathbf{U}^T \mathbf{U} -\eta' \mathbf{I} \right) \mathbf{A_0'} = 0
\end{align}