Professional Documents
Culture Documents
Least-Squares Circle Fit
Least-Squares Circle Fit
2
Given a finite set of points in R , say { (xi , yi ) | 0 ≤ i < N }, we want to find the circle that “best”
(in a least-squares sense) fits the points. Define
1 X 1 X
x = xi and y = yi
N i N i
and let ui = xi − x, vi = yi − y for 0 ≤ i < N . We solve the problem first in (u, v) coordinates,
and then transform back to (x, y).
P 2
Let the circle have center (uc , vc ) and radius R. We want to minimize S = i ( g(ui , vi ) ) , where
g(u, v) = (u − uc )2 + (v − vc )2 − α, and where α = R2 . To do that, we differentiate S(α, uc , vc ).
∂S X ∂g
= 2 g(ui , vi ) (ui , vi )
∂α i
∂α
X
= −2 g(ui , vi )
i
Thus ∂S/∂α = 0 iff
X
g(ui , vi ) = 0 Eq. 1
i
Continuing, we have
∂S X ∂g
= 2 g(ui , vi ) (ui , vi )
∂uc i
∂uc
X
= 2 g(ui , vi ) 2(ui − uc )(−1)
i
X
= −4 (ui − uc ) g(ui , vi )
i
X X
= −4 ui g(ui , vi ) + 4 uc g(ui , vi )
i i
| {z }
= 0 by Eq. 1
Thus, in the presence of Eq. 1, ∂S/∂uc = 0 holds iff
X
ui g(ui , vi ) = 0 Eq. 2
i
X
vi g(ui , vi ) = 0 Eq. 3
i
February 12, 2017 4:20 pm MST Page 2 of 3
Expanding Eq. 2 gives
X
ui u2i − 2 ui uc + u2c + vi2 − 2 vi vc + vc2 − α = 0
i
P P
Defining Su = i ui , Suu = i u2i , etc., we can rewrite this as
1 Eq. 4
uc Suu + vc Suv = (Suuu + Suvv )
2
1 Eq. 5
uc Suv + vc Svv = (Svvv + Svuu )
2
Solving Eq. 4 and Eq. 5 simultaneously gives (uc , vc ). Then the center (xc , yc ) of the circle in the
original coordinate system is (xc , yc ) = (uc , vc ) + (x, y).
N u2c + vc2 − α + Suu + Svv = 0
Thus
√
and, of course, R = α.
i xi yi ui vi
Here we have N = 7, x = 1.5, and y = 3.25. Also, Suu = 7, Suv = 21, Svv = 68.25, Suuu = 0,
Svvv = 143.81, Suvv = 31.5, Svuu = 5.25. Thus (using Eq. 4 and Eq. 5) we have the following 2 × 2
linear system for (uc , vc ):
7 21 uc 15.75
=
21 68.25 vc 74.531
Solving this system gives (uc , vc ) = (−13.339, 5.1964), and thus (xc , yc ) = (−11.839, 8.4464). Substitut-
ing these values into Eq. 6 gives α = 215.69, and hence R = 14.686. A plot of this example appears
below.