本帖最后由 hbghlyj 于 2021-6-30 14:45 编辑 以下面这组点为例:
p = {{0.07059703, 2.3311955963}, {-0.2312351881,
1.4561916933}, {1.6323255814, 0.4529926561}, {1.8817163479,
2.3923914504}, {0.274158443, 1.861522012}, {1.3099706592,
1.5983182696}, {-0.633824898, 1.7300548894}, {2.6092295121,
0.0762685712}}
----------
算法1.
AbsoluteTiming[Module[{}, S = {};
For[i = 1, i <= Length[p] - 3, i++,
For[j = i + 1, j <= Length[p] - 2, j++,
For[k = j + 1, k <= Length[p] - 1,
k++, {center, radius} = List @@ CircleThrough[p[[{i, j, k}]]];
For[l = k + 1, l <= Length[p], l++,
If[Abs[EuclideanDistance[p[[l]], center] - radius] < 1/10^3,
AppendTo[S, {i, j, k, l}]]]]]];
S /. Thread[{1, 2, 3, 4, 5, 6, 7, 8} -> {"a", "b", "c", "d", "e",
"f", "g", "h"}]]]
输出为
{0.0021478, {{"a", "b", "c", "d"}, {"a", "b", "e", "g"}, {"a", "c",
"e", "h"}, {"a", "d", "e", "f"}, {"b", "c", "g", "h"}, {"b", "d",
"f", "g"}, {"c", "d", "f", "h"}, {"e", "f", "g", "h"}}}
测试多次,实际用时0.002~0.003秒
-----------
可以看出,虽然结果正确,但是计算过程中会产生很大的误差,p中的坐标都精确到$10^{-10}$,但是作为检验的点到圆心的距离与半径之差的阈值却只能设置为$10^{-3}$(我用$10^{-4}$试过一次,会漏掉两个圆) |