如何找到点从给定的最遥远,它的边框它的、边框、最遥远

2023-09-11 03:32:59 作者:她妈为毛不喜欢我

我有一个边框,和点数它里面。我想从盒子的边缘增加其位置是距离最远的任何previously加分还有一点,还有很远。

I have a bounding box, and a number of points inside of it. I'd like to add another point whose location is farthest away from any previously-added points, as well as far away from the edges of the box.

是否有这样的事情一个共同的解决办法?谢谢!

Is there a common solution for this sort of thing? Thanks!

推荐答案

下面是一个小数学计划。

虽然只是两行code(!),你可能会需要更多的在传统的语言,以及数学库能够找到最多的功能。

Although it is only two lines of code (!) you'll probably need more in a conventional language, as well as a math library able to find maximum of functions.

我假设你不流利的数学,所以我将解释并行注释行。

I assume you are not fluent in Mathematica, so I'll explain and comment line by line.

首先,我们创建一个具有10个随机点{0,1}×{0,1}表,并将其命名为 P 。

First we create a table with 10 random points in {0,1}x{0,1}, and name it p.

p = Table[{RandomReal[], RandomReal[]}, {10}];

现在我们创建一个函数来最大化:

Now we create a function to maximize:

f[x_, y_] = Min[ x^2, 
                 y^2, 
                 (1 - x)^2, 
                 (1 -  y)^2, 
                 ((x - #[[1]])^2 + (y - #[[2]])^2) & /@ p];  

哈!语法有猫腻!让我们来解释一下:

Ha! Syntax got tricky! Let's explain:

该功能为您提供任意点{0,1}×{0,1}在 从这一点我们组P和边缘的最小距离。前四个条件是距离的边缘,最后(难读,我知道)是一组包含所有点的距离。

The function gives you for any point in {0,1}x{0,1} the minimum distance from that point to our set p AND the edges. The first four terms are the distances to the edges and the last (difficult to read, I know) is a set containing the distance to all points.

我们将下一步要做的就是最大化这个功能,所以我们将得到的地步,在最大的为自己的目标的最小距离。

What we will do next is maximizing this function, so we will get THE point where the minimum distance to our targets in maximal.

但是,首先让我们来看看在f []。如果你看一下它关键的是,你会发现它不是真正的距离,但这种距离的平方。我将其定义是这样,因为这样的功能是非常容易的最大化,结果是相同的。

But first lets take a look at f[]. If you look at it critically, you'll see that it is not really the distance, but the distance squared. I defined it so, because that way the function is much easier to maximize and the results are the same.

还要注意的是F []不是pretty的功能。如果我们在{0,1}绘制它,我们得到这样的:

Also note that f[] is not a "pretty" function. If we plot it in {0,1}, we get something like:

这就是为什么你需要一个很好的数学包装,拿出最大。

That's why you will need a nice math package to find the maximum.

数学就是这样一个漂亮的包,我们可以最大限度的东西简单:

Mathematica is such a nice package, that we can maximize the thing straightforward:

max = Maximize[{f[x, y], {0 <= x <= 1, 0 <= y <= 1}}, {x, y}];

这就是它。最大化函数返回点,并且其最近的边框/点的平方距离。

And that is it. The Maximize function returns the point, and the squared distance to its nearest border/point.

心连心!如果您需要帮助翻译成另一种语言,发表评论。

HTH! If you need help translating to another language, leave a comment.

修改

虽然我不是一个C#的人,于是想找引用和谷歌搜索后,来到了这一点:

Although I'm not a C# person, after looking for references in SO and googling, came to this:

一名候选人包 DotNumerics

您应该按照包装中提供了下面的例子:

You should follow the following example provided in the package:

 file: \DotNumerics Samples\Samples\Optimization.cs
 Example header:

  [Category("Constrained Minimization")]
  [Title("Simplex method")]
  [Description("The Nelder-Mead Simplex method. ")]
  public void OptimizationSimplexConstrained()

心连心!