Voronoi diagram on sphere
Drag Points on sphere. Press buttons to see different distributions of points on the sphere.
Have fun! :-)
#=======================
# Inspired by Daniel Mentrard
#=======================
#=======================
# Initial values
#=======================
N = 100
M = Slider(10, N, 1, 1, 160, false, true, false, false)
SetValue(M, N)
Lm = Sequence(1, M)
speed = 0.001
a = Slider(0, 6.2812, 0.001, speed, 140, false, true, false, false)
SetValue(a, 1 / 2 + sqrt(5) / 2)
#=======================
# Functions
#=======================
Px(x) = cos(pi * 2 * a * x) * sin(acos(1 - 2 * x / M))
Py(x) = sin(pi * 2 * a * x ) * sin(acos(1 - 2 * x / M))
Pz(x) = cos(acos(1 - 2 * x / M))
#=======================
# Main sphere
#=======================
O = (0,0,0)
s = Sphere(O, 1)
#=======================
# List of names for centers and spheres
#=======================
Sname = Zip("sphere"+Text(m), m, Lm)
Pname = Zip("C"+Text(m), m, Lm)
PMname = Zip("M"+Text(m), m, Lm)
#=======================
# Points and spheres
#=======================
Execute(Zip(name" = PointIn(s)", name, Pname))
Execute(Zip(name" = Midpoint("+P+", O)", name, PMname, P, Pname))
Execute(Zip(name" = Sphere( "+Mname+", 1 / 2 )", name, Sname, Mname, PMname))
Execute(Zip("ShowLabel("+name+", false)", name, Sname))
Execute(Zip("ShowLabel("+name+", false)", name, Pname))
Execute(Zip("SetVisibleInView("+name+", -1, false)", name, PMname))
Cols = Zip(random(), k, Lm)
Execute(Zip("SetDynamicColor("+name+", "+hue+", 0.85, 1, 1)", name, Sname, hue, Cols))
Execute(Zip("SetConditionToShowObject("+name+", "+k+"<=M)", name, Sname, k, Lm))
colP = "Black"
Execute(Zip("SetPointSize("+name+", 4)", name, Pname))
Execute(Zip("SetVisibleInView("+name+", 1, false)", name, Pname))
Execute(Zip("SetColor("+name+", colP)", name, Pname))
Lx = Zip( sin(pi * random()) * cos(2 * pi * random()), k, Lm)
Ly = Zip( sin(pi * random()) * sin(2 * pi * random()), k, Lm)
Lz = Zip( cos(pi * random()), k, Lm)
#Random distribution
#Execute(Zip("SetValue("+name+", ("+Px+", "+Py+", "+Pz+"))", name, Pname, Px, Lx, Py, Ly, Pz, Lz))
#Nice distribution :-)
Execute(Zip("SetValue("+name+", ( Px("+k+"), Py("+k+"), Pz("+k+") ))", name, Pname, k, Lm))
#=======================
# Settings :-)
#=======================
SetVisibleInView(M, 1, false)
SetVisibleInView(a, 1, false)
SetVisibleInView(s, -1, false)
SetVisibleInView(Px, 1, false)
SetVisibleInView(Py, 1, false)
SetVisibleInView(Pz, 1, false)
SetVisibleInView(Px, -1, false)
SetVisibleInView(Py, -1, false)
SetVisibleInView(Pz, -1, false)
SetVisibleInView(Pname, 1, false)
SetVisibleInView(PMname, 1, false)
SetVisibleInView(Sname, 1, false)
SetVisibleInView(Pname, -1, false)
SetVisibleInView(PMname, -1, false)
SetVisibleInView(Sname, -1, false)
ShowAxes(false)
ShowGrid(false)
SetBackgroundColor("GAINSBORO")