10
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ See a Wolfram Demonstrations Project here; and this thread might be also useful. $\endgroup$ – corey979 Mar 7 '17 at 13:45
  • $\begingroup$ @corey979 I found the Wolfram Demonstration for this, but for the life of me I can't extract the algorithm from it. $\endgroup$ – Morgan Mar 7 '17 at 17:16
  • 2
    $\begingroup$ @Morgan I believe it uses a Voronoi tesselation in 3D and takes its intersection with the sphere. It is not clear to me if that is the same what one would get when measuring distances along geodesics on the sphere. $\endgroup$ – Szabolcs Mar 9 '17 at 13:07
  • $\begingroup$ This link could be interesting. $\endgroup$ – Dunlop Mar 29 '17 at 12:53
11
$\begingroup$

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

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Very cool. I guess I should use this to do Lebesgue integration on a sphere. $\endgroup$ – Anton Antonov Apr 7 '17 at 14:57
  • $\begingroup$ 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.) $\endgroup$ – J. M.'s technical difficulties Apr 7 '17 at 17:03
  • $\begingroup$ Please see the section "Algorithm walk through" in this blog post of mine ("Adaptive numerical Lebesgue integration by set measure estimates"). $\endgroup$ – Anton Antonov Apr 7 '17 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.