Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a little <a href="http://www.wolfram.com/mathematica/" rel="noreferrer">Mathematica</a> program. </p> <p>Although it is only two lines of code (<b>!</b>) you'll probably need more in a conventional language, as well as a math library able to find maximum of functions. </p> <p>I assume you are not fluent in Mathematica, so I'll explain and comment line by line. </p> <p>First we create a table with 10 random points in {0,1}x{0,1}, and name it <b>p</b>. </p> <pre><code>p = Table[{RandomReal[], RandomReal[]}, {10}]; </code></pre> <p>Now we create a function to maximize: </p> <pre><code>f[x_, y_] = Min[ x^2, y^2, (1 - x)^2, (1 - y)^2, ((x - #[[1]])^2 + (y - #[[2]])^2) &amp; /@ p]; </code></pre> <p>Ha! Syntax got tricky! Let's explain: </p> <p>The function gives you for any point in {0,1}x{0,1} the <b>minimum distance</b> 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. </p> <p>What we will do next is <b>maximizing</b> this function, so we will get THE point where the minimum distance to our targets in maximal. </p> <p>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. </p> <p>Also note that f[] is not a "pretty" function. If we plot it in {0,1}, we get something like: </p> <p><img src="https://i.stack.imgur.com/PerJJ.png" alt="alt text"> </p> <p>That's why you will need a nice math package to find the maximum. </p> <p>Mathematica is such a nice package, that we can maximize the thing straightforward: </p> <pre><code>max = Maximize[{f[x, y], {0 &lt;= x &lt;= 1, 0 &lt;= y &lt;= 1}}, {x, y}]; </code></pre> <p>And that is it. The Maximize function returns the point, and the squared distance to its nearest border/point. </p> <p><img src="https://i.stack.imgur.com/4YBvf.png" alt="alt text"> </p> <p>HTH! If you need help translating to another language, leave a comment. </p> <p><b>Edit</b></p> <p>Although I'm not a C# person, after looking for references in SO and googling, came to this:</p> <p>One candidate package is <a href="http://www.dotnumerics.com/Downloads.aspx" rel="noreferrer">DotNumerics</a></p> <p>You should follow the following example provided in the package:</p> <pre><code> file: \DotNumerics Samples\Samples\Optimization.cs Example header: [Category("Constrained Minimization")] [Title("Simplex method")] [Description("The Nelder-Mead Simplex method. ")] public void OptimizationSimplexConstrained() </code></pre> <p>HTH!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload