8
$\begingroup$

VoronoiMesh seems useless because it does not even have an option DistanceFunction.

This post is interesting but I wish to make usual (polygonal) diagram.

I tried using Nearest and DensityPlot (as shown in the built-in example). But have no idea how to make weighted DistanceFunction.

UPD Let $p_i$ be a seed point, $w_i$ - its weight and $p$ - any point. So I guess DistanceFunction should look like EuclideanDistance[p_i, p]/w_i.

$\endgroup$
2
  • $\begingroup$ Have you see ref/ListDensityPlot->Neat Examples? $\endgroup$ Commented Sep 21, 2016 at 6:31
  • $\begingroup$ @yode Thanks, but I mean the dependence of the area on the weights of points, not color etc. $\endgroup$ Commented Sep 21, 2016 at 6:44

2 Answers 2

7
$\begingroup$

Firstly this article explains that the weighted Voronoi diagram cannot be polygonal.
And we will have to create our own Nearest function to make it in Mathematica.

myNearest[pts_, wts_, p_] := pts[[First@
Ordering@MapThread[(EuclideanDistance[#1, p]/#2) &, {pts, wts}]]];
n = 5; pts = RandomReal[{-1, 1}, {n, 2}];
wtsSet = {{1, 1, 1, 1, 1}, {1, 2, 1, 1, 1}, {1, 3, 1, 1, 1}, {1, 4, 1, 
1, 1}};
DensityPlot[myNearest[pts, #, {x, y}], {x, -1, 1}, {y, -1, 1}, 
PlotPoints -> 100, Epilog -> {Point@pts}, 
ColorFunction -> "Rainbow", ImageSize -> {300, 300}] & /@ wtsSet

enter image description here

$\endgroup$
2
  • $\begingroup$ thank you for this answer, You wrote your own Nearest: very nice. :) $\endgroup$ Commented Sep 22, 2016 at 1:04
  • $\begingroup$ Thanks, your example helps me very much $\endgroup$ Commented Sep 22, 2016 at 7:25
5
$\begingroup$

I post this to show a 'user-defined' distance function for Voronoi diagram.

r = RandomReal[1, {20, 2}];
dfun[m_][{x_, y_}, {a_, b_}] := {x - a, y - b}.m.{x - a, y - b}
nr[m_] := 
 Nearest[Thread[r -> N@Range[Length@r]], DistanceFunction -> dfun[m]]

nfun[m_, {x_, y_}] := nr[m][{x, y}][[1]]
tab = Table[{MatrixForm[matrix], 
    Quiet@DensityPlot[nfun[matrix, {x, y}], {x, 0, 1}, {y, 0, 1}, 
      PlotPoints -> 100, 
      Epilog -> {Point@r}]}, {matrix, {IdentityMatrix[
      2], {{10, 0}, {0, 2}}, {{5, 1}, {3, 2}}}}];
Grid[tab, Frame -> All]

enter image description here

Apologies for any errors or misunderstanding.

$\endgroup$
2
  • $\begingroup$ Thanks. But the function dfun[] is symmetric about {x,y} and {a,b}. How is it possible to use weights of seeds? $\endgroup$ Commented Sep 21, 2016 at 8:41
  • $\begingroup$ @lesobrod The point of dfun was to illustrate how you can use a user defined distance function not what I actually used. I suggest you try whatever metric you want and re-try using Nearest. Test that the function does what you want it to do. Good luck :) $\endgroup$ Commented Sep 21, 2016 at 8:58

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.