I want to compute the Voronoi diagram on the unit disk, using the hyperbolic metric. So, I want to input a list of points and obtain a plot of the cells associated with each of the points.
I defined the metric:
HyperbolicDistance[{a1_, b1_}, {a2_, b2_}] :=
Module[{d, dist},
d = 2*((EuclideanDistance[{a1, b1}, {a2,
b2}]^2)/((1 - EuclideanDistance[{a1, b1}, {0, 0}]^2)*(1 -
EuclideanDistance[{a2, b2}, {0, 0}]^2)));
dist = ArcCosh[1 + d]; Return[dist]]
Now, I define the regions, with the list of centers defined by pts
cells = And @@@
Table[HyperbolicDistance[pts[[i]], {x, y}] <=
HyperbolicDistance[pts[[j]], {x, y}], {i, n}, {j,
Complement[Range[n], {i}]}];
Then, I plot using RegionPlot
:
RegionPlot[{cells, x^2 + y^2 < 1}, {x, -1, 1}, {y, -1, 1},
Frame -> False, PlotPoints -> Automatic]
I get some warning messages:
LessEqual::nord: Invalid comparison with 0.844796 +3.14159 I attempted. >>
which is due to the fact that the metric is defined only on the unit disk and RegionPlot
is evaluating it on points in the unit square with $-1<x<1,\; -1<y<1$
Is there a way I can evaluate RegionPlot
in the unit disk, so as to avoid getting this message?
This method is quite inefficient and inaccurate. I can increase the accuracy of the picture by increasing PlotPoints
and MaxRecursion
, but both are increasing the evaluation time immensely. I am not sure, but I guessed that using the Nearest
function to evaluate which of the points in the list of Voronoi is closest to a given point $(x,y)$ might improve the code. So I used the DistanceFunction
to transform the metric used in Nearest
, but because RegionPlot
is evaluating it at points where the metric is not valid, so I get the errors like Nearest::nearuf: The user-supplied distance function HyperbolicDistance does not give a real numeric distance when applied to the point pair {1,1} and {-0.304667,0.852203}. >>
.
Is there a way to improve my code to reduce run time?
I am quite new to Mathematica, so any suggestions or insights would be helpful. Thanks!
Nearest[]
for making fake Voronoi diagrams myself. I can post the code for that if you want it. $\endgroup$VoronoiDiagram[]
does not currently support other metrics at the moment. So you wouldn't mind my posting a fake? $\endgroup$Polygon
instead ofRegionPlot
. $\endgroup$