我想知道如何解决以下问题。
在任意两点之间的距离不得小于 1 的条件下,在边为 的正方形内随机排列 个点。
我想看看怎么解决。
我想知道如何解决以下问题。
在任意两点之间的距离不得小于 1 的条件下,在边为 的正方形内随机排列 个点。
我想看看怎么解决。
编辑:
执行第 2 步的最佳方法取决于很多事情。如果没有太多点,您可以计算(使用 matlab 语法):
dmin=1;
for i=1:n
for j=i+1:n
dmin = min( dmin,norm( p(i,:)-p(j,:) ) );
end
end
这种蛮力方法将花费 $\mathcal{O}(n^2)$ 时间。如果你有很多很多点,使用分治法的 $\mathcal{O}(n\log(n))$ 算法可能是值得的。有关更多信息,请参阅维基百科页面。 time. If you have many, many points it may be worth using an algorithm using a divide and conquer approach. See
如果 $n$ 太大并且平方器 $a$ 的边长是固定的,那么可能无法解决您的问题。如果您愿意增加正方形的大小以适应点,那么@DougLipinski 的解决方案将起作用。 is too large and the side length of your squarer is fixed then there may not be a solution to your problem. If you are willing to increase the size of the square to fit the points then the solution by @DougLipinski will work.
如果正方形大小是固定的(这就是我假设您首先提出问题的原因),那么他的解决方案中的重新缩放步骤可能会将点推到正方形之外。
您实际上可以通过计算构成正方形镶嵌的点数来估计适合您的正方形内的点数的上限。
找到可以包含距离不小于 $1$ 的 $n$ 个点的最小 $a$-square 的问题等价于正方形问题中的圆打包,请参见例如圆打包和点打包之间的等价性。有关此问题的信息也可以在Circle Packing中找到,并在The best known packings of equal circles in a square中找到最佳或最知名的解决方案列表。-square that can contain points whose distance is not less than is equivalent to the
据我所知,这是一个仍未解决的问题:OP 问题的答案取决于所需解决方案与最佳解决方案的接近程度,或者对于固定的 $a$,$n$ 有多大。 for fixed .
如果我们寻找一个远非最优的解决方案,Doug 的答案可能是可行的。相反,如果我们接近最优极限,随机分散和重新缩放方法将给出不可行的解决方案,正如dpmcmlxxvi在他的回答中指出的那样。
问题不是以存在唯一或最佳答案的方式定义的,但我将在 $n$ 足够大的情况下按照以下方式进行,但仍不太接近最优/最佳解决方案。 is large enough, but still not too close to the optimal/best known solution.
将 $n$ 个点排列在包络近似为正方形的六边形格子上。(请参阅OEIS A093766了解此晶格的性质。) points on an hexagonal lattice whose envelope is approximately square. (See
如果这个正方形的边小于 $a$,重新调整它以紧密地适合 $a$ 正方形。, rescale it to tightly fit inside the square.
重新缩放后应用小扰动,以便为解决方案提供“随机”外观。
如果 $n$ 接近最佳/最佳已知解决方案,则只需从已知解决方案列表中进行表查找。 is close to the optimal/best know solution, than simply do a table lookup from a list of the known solutions.
看起来您可能想要使用 Halton 序列或 Sobol 序列。这些是分布在正方形中的点集,看起来是随机的,但要避免任何两个点靠得太近。
维基百科上的文章是一个好的开始。