Function Repository Resource:

# CircleFit

Find the best-fit circle for a set of points

Contributed by: Sander Huisman
 ResourceFunction["CircleFit"][pts] returns the best-fit circle for the points pts. ResourceFunction["CircleFit"][w→pts] returns the best-fit circle for the points pts having the weights w. ResourceFunction["CircleFit"][w→pts,"Association"] returns an association with the center, the radius, the Circle, a pure function etc.

## Details

ResourceFunction["CircleFit"] returns a Circle object or an Association.
For 1 point, a circle at that point with 0 radius is returned.
For 2 points, a circle at the midpoint with a radius equal to half the distance between the points is returned.
For 3 points that are not collinear, an exact solution will be returned.
For 4 or more points pts, ResourceFunction["CircleFit"] returns the circle centered at {x,y} with radius r that minimizes .
For 4 or more points pts and weights w, ResourceFunction["CircleFit"] returns the circle centered at {x,y} with radius r that minimizes .

## Examples

### Basic Examples (2)

Find the circle through 4 points and visualize the result:

 In[1]:=
 Out[1]=

Find the best-fitting circle for a 2500 points:

 In[2]:=
 Out[2]=

### Scope (2)

Specify weights:

 In[3]:=
 Out[3]=

Return an Association with all the details:

 In[4]:=
 Out[4]=

### Properties and Relations (1)

For 2 points, the center of the circle is the midpoints of the points:

 In[5]:=
 Out[5]=

### Possible Issues (3)

When no points are given, a Failure object is returned:

 In[6]:=
 Out[6]=

When 3 points are given and they are collinear, a Failure object is returned:

 In[7]:=
 Out[7]=

The case of multiple collinear points results in circle that is far away with a large radius:

 In[8]:=
 Out[8]=

### Neat Examples (1)

Find the best-fitting circle for points clustered around a circular arc:

 In[9]:=
 Out[9]=

SHuisman

## Version History

• 1.1.0 – 17 May 2021

## Author Notes

First an estimate is found by minimizing . After that the real problem is minimized using the estimate as a starting points, .