Sunteți pe pagina 1din 3

October 24, 2006 10:22 am MDT Page 1 of 3

Least-Squares Circle Fit


R. Bullock
Given a nite set of points in R
2
, say { (x
i
, y
i
) | 0 i < N }, we want to nd the circle that best
(in a least-squares sense) ts the points. Dene
x =
1
N

i
x
i
and y =
1
N

i
y
i
and let u
i
= x
i
x, v
i
= y
i
y for 0 i < N. We solve the problem rst in (u, v) coordinates,
and then transform back to (x, y).
Let the circle have center (u
c
, v
c
) and radius R. We want to minimize S =

i
( g(u
i
, v
i
) )
2
, where
g(u, v) = (u u
c
)
2
+ (v v
c
)
2
, and where = R
2
. To do that, we differentiate S(, u
c
, v
c
).
S

= 2

i
g(u
i
, v
i
)
g

(u
i
, v
i
)
= 2

i
g(u
i
, v
i
)
Thus S/ = 0 iff

i
g(u
i
, v
i
) = 0
Eq. 1
Continuing, we have
S
u
c
= 2

i
g(u
i
, v
i
)
g
u
c
(u
i
, v
i
)
= 2

i
g(u
i
, v
i
) 2(u
i
u
c
)(1)
= 4

i
(u
i
u
c
) g(u
i
, v
i
)
= 4

i
u
i
g(u
i
, v
i
) + 4 u
c

i
g(u
i
, v
i
)
. .
= 0 by Eq. 1
Thus, in the presence of Eq. 1, S/u
c
= 0 holds iff

i
u
i
g(u
i
, v
i
) = 0
Eq. 2
Similarly, requiring S/v
c
= 0 gives

i
v
i
g(u
i
, v
i
) = 0
Eq. 3
October 24, 2006 10:22 am MDT Page 2 of 3
Expanding Eq. 2 gives

i
u
i
_
u
2
i
2 u
i
u
c
+ u
2
c
+ v
2
i
2 v
i
v
c
+ v
2
c

= 0
Dening S
u
=

i
u
i
, S
uu
=

i
u
2
i
, etc., we can rewrite this as
S
uuu
2 u
c
S
uu
+ u
2
c
S
u
+ S
uvv
2 v
c
S
uv
+ v
2
c
S
u
S
u
= 0
Since S
u
= 0 , this simplies to
u
c
S
uu
+ v
c
S
uv
=
1
2
(S
uuu
+ S
uvv
)
Eq. 4
In a similar fashion, expanding Eq. 3 and using S
v
= 0 gives
u
c
S
uv
+ v
c
S
vv
=
1
2
(S
vvv
+ S
vuu
)
Eq. 5
Solving Eq. 4 and Eq. 5 simultaneously gives (u
c
, v
c
). Then the center (x
c
, y
c
) of the circle in the
original coordinate system is (x
c
, y
c
) = (u
c
, v
c
) + (x, y).
To nd the radius R, expand Eq. 1:

i
_
u
2
i
2 u
i
u
c
+ u
2
c
+ v
2
i
2 v
i
v
c
+ v
2
c

= 0
Using S
u
= S
v
= 0 again, we get
N
_
u
2
c
+ v
2
c

_
+ S
uu
+ S
vv
= 0
Thus
= u
2
c
+ v
2
c
+
S
uu
+ S
vv
N
Eq. 6
and, of course, R =

.
See the next page for an example!
October 24, 2006 10:22 am MDT Page 3 of 3
Example : Lets take a few points from the parabola y = x
2
and t a circle to them. Heres a table
giving the points used:
i x
i
y
i
u
i
v
i
0 0.000 0.000 -1.500 -3.250
1 0.500 0.250 -1.000 -3.000
2 1.000 1.000 -0.500 -2.250
3 1.500 2.250 0.000 -1.000
4 2.000 4.000 0.500 0.750
5 2.500 6.250 1.000 3.000
6 3.000 9.000 1.500 5.750
Here we have N = 7, x = 1.5, and y = 3.25. Also, S
uu
= 7, S
uv
= 21, S
vv
= 68.25, S
uuu
= 0,
S
vvv
= 143.81, S
uvv
= 31.5, S
vuu
= 5.25. Thus (using Eq. 4 and Eq. 5) we have the following 2 2
linear system for (u
c
, v
c
):
_
7 21
21 68.25
_ _
u
c
v
c
_
=
_
15.75
74.531
_
Solving this system gives (u
c
, v
c
) = (13.339, 5.1964), and thus (x
c
, y
c
) = (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.