これは、いくつかの近似を見つけることは非常に簡単です:
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
を説明:平均xに円の中心を置き、あなたのポイントのy座標を意味します。次に、各点について、中心までの距離を決定し、すべての点にわたって平均をとる。それはあなたの半径です。
この完全なスクリプト:
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()
はこのプロットを生成します。
あなたは測定誤差とポリゴンを持っているので、これは良い動作します。あなたのポイントが角度[0,2pi[
にほぼ均等に分配されていないと、パフォーマンスが悪くなります。
さらに一般的には、最適化を使用できます。
おそらく、最小二乗法を使用できます。最小二乗法を用いて円を見つけることについて書かれた論文の[ここはPDFファイルです](http://www.emis.de/journalals/BBMS/Bulletin/sup962/gander.pdf) あなたがやっていることのためには、それは少し複雑かもしれません。ポイントがおおよそ円であれば、おそらくもっとうまくいくより基本的な方法を見つけることができます。 – William
あなたがすでに中心を知っていれば、最小の四角形が行く方法のようです。これは本質的に極座標の曲線適合問題になります。 – Kevin
[ハフ変換](http://ja.wikipedia.org/wiki/Hough_transform)を確認してください。それは簡単な円検出ソリューションにつながります。 – Simon