# How to create weighted Voronoi diagram?

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.

• Have you see ref/ListDensityPlot->Neat Examples?
– yode
Sep 21 '16 at 6:31
• @yode Thanks, but I mean the dependence of the area on the weights of points, not color etc. Sep 21 '16 at 6:44

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@
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


• thank you for this answer, You wrote your own Nearest: very nice. :) Sep 22 '16 at 1:04
• Thanks, your example helps me very much Sep 22 '16 at 7:25

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]


Apologies for any errors or misunderstanding.

• Thanks. But the function dfun[] is symmetric about {x,y} and {a,b}. How is it possible to use weights of seeds? Sep 21 '16 at 8:41
• @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 :) Sep 21 '16 at 8:58