It is very easy to find some approximation:
def find_circle_deterministically(x,y): center = x.mean(), y.mean() radius = np.sqrt((x-center[0])**2 + (y-center[1])**2).mean() return center, radius
Explanation: Put the center of the circle at the average of x and mean y of your points. Then, for each point, determine the distance to the center and take the average value at all points. This is your radius.
This full script:
import numpy as np import matplotlib.pyplot as plt n_points = 10 radius = 4 noise_std = 0.3 angles = np.linspace(0,2*np.pi,n_points,False) x = np.cos(angles) * radius y = np.sin(angles) * radius x += np.random.normal(0,noise_std,x.shape) y += np.random.normal(0,noise_std,y.shape) plt.axes(aspect="equal") plt.plot(x,y,"bx") def find_circle_deterministically(x,y): center = x.mean(), y.mean() radius = np.sqrt((x-center[0])**2 + (y-center[1])**2).mean() return center, radius center, radius2 = find_circle_deterministically(x,y) angles2 = np.linspace(0,2*np.pi,100,True) x2 = center[0] + np.cos(angles2) * radius2 y2 = center[1] + np.sin(angles2) * radius2 plt.plot(x2,y2,"r-") plt.show()
creates this graph:

This will work well as you have polygons with measurement errors. If your points are not evenly distributed in the corners [0,2pi[ , this will work poorly.
More generally, you can use optimization.
Thorsten kranz
source share