Function Repository Resource:

HyperbolicDistance

Source Notebook

Give the distance between two points in hyperbolic space

Contributed by: Jan Mangaldan

ResourceFunction["HyperbolicDistance"][u,v,"metric"]

gives the distance between vectors u and v in hyperbolic space, using the specified metric.

Details

The following metrics are supported:
"Beltrami"Beltrami–Klein disk metric
"HalfPlane"Poincaré half-plane metric
"Poincare"Poincaré disk metric

Examples

Basic Examples (2) 

Distance between two vectors on the Poincaré disk:

In[1]:=
ResourceFunction["HyperbolicDistance"][{a, b}, {x, y}, "Poincare"]
Out[1]=

Distance between numeric vectors on the Poincaré disk:

In[2]:=
ResourceFunction[
 "HyperbolicDistance"][{3/10, 2/5}, {5/26, 6/13}, "Poincare"]
Out[2]=

Scope (2) 

Distance between two points on the Beltrami–Klein ball:

In[3]:=
ResourceFunction[
 "HyperbolicDistance"][{1/18, 1/9, 1/9}, {1/12, 1/12, 1/
  6}, "Beltrami"]
Out[3]=

Distance between two points in the Poincaré half-plane model:

In[4]:=
ResourceFunction["HyperbolicDistance"][{0, 2}, {1, 1}, "HalfPlane"]
Out[4]=

Applications (2) 

Cluster data on the Poincaré ball:

In[5]:=
FindClusters[RandomPoint[Ball[], 20], DistanceFunction -> (ResourceFunction["HyperbolicDistance"][#1, #2, "Poincare"] &)]
Out[5]=

Visualize the clusters:

In[6]:=
ListPointPlot3D[%]
Out[6]=

Possible Issues (1) 

If at least one of the points supplied is a point at infinity, HyperbolicDistance returns Infinity:

In[7]:=
ResourceFunction[
 "HyperbolicDistance"][{1., 0.}, {3., 2.}, "HalfPlane"]
Out[7]=

Neat Examples (1) 

Visualize the Voronoi diagram of points on the Beltrami-Klein and Poincaré models:

In[8]:=
bPts = RandomPoint[Disk[], 20];
pPts = #/(1 + Sqrt[1 - (SquaredEuclideanDistance @@ #)]) & /@ bPts;
bNF = Nearest[bPts -> "Distance", DistanceFunction -> (ResourceFunction["HyperbolicDistance"][#1, #2, "Beltrami"] &)]; pNF = Nearest[pPts -> "Distance", DistanceFunction -> (ResourceFunction["HyperbolicDistance"][#1, #2, "Poincare"] &)];
In[9]:=
GraphicsRow[{DensityPlot[
   Module[{res = bNF[{x, y}, 2], tmp}, tmp = 1 - ResourceFunction["RationalSmoothStep"][
       Clip[Rescale[res[[1]], {-6, 6}], {0, 1}]]; Max[tmp, res[[1]]/res[[2]]]], {x, y} \[Element] Disk[{0, 0}, 0.99], PlotLabel -> "Beltrami", PlotPoints -> 150, PlotRange -> All],
  DensityPlot[
   Module[{res = pNF[{x, y}, 2], tmp}, tmp = 1 - ResourceFunction["RationalSmoothStep"][
       Clip[Rescale[res[[1]], {-6, 6}], {0, 1}]]; Max[tmp, res[[1]]/res[[2]]]], {x, y} \[Element] Disk[{0, 0}, 0.99], PlotLabel -> "Poincare", PlotPoints -> 150, PlotRange -> All]}]
Out[9]=

Version History

  • 1.0.0 – 22 March 2021

Related Resources

License Information