我需要確定覆蓋一組 10 個點的最小圓(特別是所述圓的直徑)。 有誰知道如何在 JSL 中計算這個值?
非常感謝您的見解! 我還沒有完全實現這一點,但這似乎對我有用。
不知道如何計算精確答案,但這似乎迭代到近似值。
更新,2019 年 2 月 15 日 - 如果圓上只有兩個點,則效果不佳,請參見最後的圖片。
<STRIKE>see slightly better JSL below</STRIKE>
Circle shrunk to fit the pointsCircle shrunk to fit the points圓圈縮小以適應點
以下是效果不佳的兩點情況:
can't find the center very well with only two pointscan't find the center very well with only two points只有兩個點不能很好地找到中心
您可以對此進行測試,並在第三個最近的點不在半徑時取這兩個點的平均值,但這會變得笨拙並且可能會出現更多問題。 如果您需要確切的答案,您應該查看維基百科的答案。 https://en.wikipedia.org/wiki/Smallest-circle_problem
可能很難... https://stackoverflow.com/questions/33443006/understanding-algorithm-for-finding-the-smallest-circle-enending-points
這個稍微好一點,但是Welzl 演算法應該在更短的時間內給出準確的答案:
points = J( 33, 2, Random normal( 50, 20 ) ); // make 33 random points
nrows = N Rows( points );
kdt = KDTable( points ); // make a nearest row look up table
center = Mean( points[0, 1] ) || Mean( points[0, 2] ); // pick a starting point
radius = 1e99; // make it big enough
fraction = .2; // fractional distance to move the center towards farthest point
For( i = 1, i < 1000, i++, // usually stops around 700
{indexes, distances} = kdt << knearestrows( nrows, center ); // just need farthest point, but get them all
farthest = indexes[nrows]; // last one is far away
howfar = distances[nrows];
If( howfar > radius, // if oscillating, make the fraction smaller
fraction = fraction * .9; // .5 stops the iterations too soon and gives really poor answers for 2-points on circle case
Show( i, fraction );
If( fraction < 1e-15, // good enough
Break()
);
);
radius = howfar;
// move slightly toward the farthest point
center = center + fraction * (points[farthest, 0] - center);
);
New Window( "Example",
Graph Box(
Frame Size( 500, 500 ),
X Scale( -30, 130 ),
Y Scale( -30, 130 ),
Marker( Marker State( 3 ), points[0, 2], points[0, 1] );
Pen Color( "Blue" );
Circle( {center[2], center[1]}, radius );
fill Color( "red" );
Pen Color( "red" );
Circle( {center[2], center[1]}, 2.0,"FILL" );
for(i=nrows,i>nrows-3,i--,
for(j=i,j>nrows-3,j--,
line({points[indexes[i],2],points[indexes[i],1]},{points[indexes[j],2],points[indexes[j],1]})
)
);
)
);
center is closercenter is closer中心更近
@kvnsngr ,
好吧,我真的很想幫助你,但是我建議並要求你嘗試並至少就你希望社區提供幫助的內容提出良好的偽代碼。 如果您能提出偽代碼,我或其他社群成員可以指導如何在 JMP 中實現偽代碼。
請原諒,我對這個主題不是很了解。 但我發現了一篇論文Sven Skyum 似乎有一個有效的演算法。
@kvnsngr ,
你指的是最小外接圓問題嗎? 如果是,您是否有想要在 JMP 中實現的演算法?