10

If I have a set of points which lie on the unit sphere:

data = Normalize /@ RandomReal[1, {100, 3}]

How do I go about computing Voronoi cells on a sphere? I know that there are algorithms in other languages, but are they difficult to implement in Mathematica?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Morgan
  • 525
  • 2
  • 10

1 Answers1

12

Here is a modernization of Maxim Rytin's code for generating a spherical Voronoi diagram, as featured in his Wolfram Demonstration:

(* http://mathematica.stackexchange.com/a/10994 *)
arc[center_?VectorQ, {start_?VectorQ, end_?VectorQ}] := Module[{ang, co, r},
    ang = VectorAngle[start - center, end - center];
    co = Cos[ang/2]; r = EuclideanDistance[center, start];
    BSplineCurve[{start, center + r/co Normalize[(start + end)/2 - center], end}, 
                 SplineDegree -> 2, SplineKnots -> {0, 0, 0, 1, 1, 1},
                 SplineWeights -> {1, co, 1}]]

BlockRandom[SeedRandom[0, Method -> "MersenneTwister"]; (* for reproducibility *)
            points = {2 π #1, ArcCos[2 #2 - 1]} & @@@ RandomReal[1, {50, 2}];]

sp = Append[Sin[#2] Through[{Cos, Sin}[#1]], Cos[#2]] & @@@ points;
ch = ConvexHullMesh[sp];
verts = MeshCoordinates[ch]; polys = First /@ MeshCells[ch, 2];

voro = Normalize[Cross[verts[[#2]] - verts[[#1]], verts[[#3]] - verts[[#1]]]] & @@@ polys;
edges = arc[{0, 0, 0}, voro[[##]]] & /@ 
        Select[Subsets[Range[Length[polys]], {2}],
               Length[Intersection @@ polys[[#]]] >= 2 &];

Graphics3D[{{Opacity[.75], Sphere[]}, {AbsoluteThickness[2], edges},
            {Red, Sphere[sp, 0.02]}}, Boxed -> False]

spherical Voronoi diagram

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
  • Very cool. I guess I should use this to do Lebesgue integration on a sphere. – Anton Antonov Apr 07 '17 at 14:57
  • It still has some way to go: I've only determined the edges, but not the spherical polygons that comprise the cells. I don't think I've heard of Voronoi being used for Lebesgue integration. Can you point me to some references I can read? (My interest in this, OTOH, is to eventually write a spherical version of Lloyd's algorithm.) – J. M.'s missing motivation Apr 07 '17 at 17:03
  • Please see the section "Algorithm walk through" in this blog post of mine ("Adaptive numerical Lebesgue integration by set measure estimates"). – Anton Antonov Apr 07 '17 at 19:22