4

I am looking for an algorithm to optimally distribute N points on the surface of a sphere (not randomly, I speak about optimal distribution in the sense of the Tammes problem). I want to do that in C++, but the problem is not a language problem, it is an algorithmic problem. Here is the algorithm I currently use (in python):

# Function to distribute N points on the surface of a sphere 
# (source: http://www.softimageblog.com/archives/115)
def uniform_spherical_distribution(N): 
    pts = []   
    inc = math.pi * (3 - math.sqrt(5)) 
    off = 2 / float(N) 
    for k in range(0, int(N)): 
        y = k * off - 1 + (off / 2) 
        r = math.sqrt(1 - y*y) 
        phi = k * inc 
        pts.append([math.cos(phi)*r, y, math.sin(phi)*r])   
    return pts

For a large number of points the visual result seems quite good but for a low number of points (between 2 and 10), the result does not seem good at all (more points in a hemisphere). Is there a way to enhance the algorithm to be also ok for a low number of points... (the answers can be in C, C++ or Python).

user1118321
  • 25,567
  • 4
  • 55
  • 86
Vincent
  • 57,703
  • 61
  • 205
  • 388
  • @andand I am not sure its a duplicate. He wants *optimal* distribution for `N<=10`. That's different from the answers I have read so far. If I am mistaken, please point out which answer gives the way to compute the optimal distribution. – Ali Feb 24 '14 at 23:04
  • @Ali OP requests a packing in the sense of the Tammes problems which the provided linke defines as "a problem in packing a given number of circles on the surface of a sphere such that the minimum distance between circles is maximized". The comment on by "BlueRaja - Danny Pflughoeft" to the post I suggested as a duplicate uses almost the same exact phrasing to describe what that poster is looking for and then offers the highest rated answer addressing that particular problem. – andand Feb 25 '14 at 05:13
  • @andand Well, I disagree: Vincent asks for *optimal* distributions, those answers will give *some approximate* distributions. Please also check my answer; I couldn't find these results elsewhere. – Ali Feb 25 '14 at 16:50
  • @Ali have you checked all answers? – Luka Rahne Feb 25 '14 at 17:27
  • @LukaRahne Yes, and I don't see my mistake. Please provide a link explicitly to that particular answer that gives the same information as my answer, that is, it provides a way to get the **optimal** distribution for small N. [This one](http://stackoverflow.com/a/9606368/341970) is close but I don't find it too helpful in Vincent's case. – Ali Feb 25 '14 at 18:23
  • @Ali From my info this problem still at this time remains open problem. In 2010 there is proof of optimal solution of 5 electrons distribution. http://arxiv.org/abs/1001.3702 .It has 66 pages. – Luka Rahne Feb 25 '14 at 19:13
  • @LukaRahne Interesting. Although note that Vincent is interested in the Tammes problem and you link to the Thompson problem. According to these [slides](http://www-lp.fmf.uni-lj.si/plestenjak/talks/preddvor.pdf) both the Thompson and the Tammes problem are solved for `N=2..6` and `12`. (Probably these slides are newer than the paper you link to.) In any case, I would distinguish between (i) optimal in the rigorous mathematical sense and (ii) optimal with 99.99% confidence, and even if it turns out to be suboptimal, it is still something sensible. My answer is the latter. – Ali Feb 25 '14 at 22:34
  • @Ali Paper is from 2001 http://www-lp.fmf.uni-lj.si/plestenjak/papers.htm . I do not believe that here is much more to add except new breakthrough in this field. Answers in linked question have plenty of high quality answers with numerous links. – Luka Rahne Feb 25 '14 at 22:46
  • @LukaRahne I can only repeat myself: "Please provide a link explicitly to that particular answer that gives the same information as my answer, that is, it provides a way to get the optimal distribution for small N. [This one](http://stackoverflow.com/a/9606368/341970) is close but I don't find it too helpful in Vincent's case." – Ali Feb 25 '14 at 22:55
  • Since there is no exacts solution known any numerical method should work. There is whole thread on that. – Luka Rahne Feb 25 '14 at 22:58

1 Answers1

2

Brute force probably works if all you need is the low number of points. By brute force I mean precomputing the solutions for 2..10 and looking them up in an array if N<=10.

For small Ns like that, it should be possible to solve the mathematical optimization problem distributing your points optimally. You need multistart but for small Ns it should not be a problem. Here is my attempt in AMPL:

param N;

var x{1..N};
var y{1..N};
var z{1..N};

var d;

param xbest{1..N};
param ybest{1..N};
param zbest{1..N};
param dbest;

maximize obj: d;

all_points_on_the_sphere{i in 1..N}:
  x[i]^2 + y[i]^2 + z[i]^2 = 1;

all_pairs{i in 1..N, j in 1..N : i<j}:
  (x[i]-x[j])^2 + (y[i]-y[j])^2 + (z[i]-z[j])^2 >= d;

fix_first_x:  x[1] = 1;
fix_first_y:  y[1] = 0;
fix_first_z:  z[1] = 0;  
fix_second_z: z[2] = 0;

#############################################

option show_stats 1;
option presolve 10;
option substout 1;
option var_bounds 2;
#option nl_comments 0;
#option nl_permute 0;
option display_precision 0;

option solver "/home/ali/ampl/ipopt";

for {k in 2..10} {
    let N := k;  
    solexpand _con;
    let dbest := -1.0;
    # Multistart
    for {1..2000} {
        for {j in 1.._snvars}
            let _svar[j] := Uniform(-1, 1);
        let d := N;     

        solve;

        if (solve_result_num < 200 and d > dbest) then {
            let dbest := d;
            for {i in 1..N} {
                let xbest[i] := x[i];
                let ybest[i] := y[i];
                let zbest[i] := z[i];
            }
        }
    }

    print "@@@";
    printf "N=%d, min distance %6f\n", N, sqrt(dbest);

    for {i in 1..N}
        printf "(%9.6f, %9.6f, %9.6f)\n", xbest[i], ybest[i], zbest[i];
}

It took 5 minutes to run this script on my machine and the solutions are:

N=2, min distance 2.000000
( 1.000000,  0.000000,  0.000000)
(-1.000000,  0.000000,  0.000000)

N=3, min distance 1.732051
( 1.000000,  0.000000,  0.000000)
(-0.500000,  0.866025,  0.000000)
(-0.500000, -0.866025,  0.000000)

N=4, min distance 1.632993
( 1.000000,  0.000000,  0.000000)
(-0.333333, -0.942809,  0.000000)
(-0.333333,  0.471405, -0.816497)
(-0.333333,  0.471405,  0.816497)

N=5, min distance 1.414214
( 1.000000,  0.000000,  0.000000)
(-0.208840,  0.977950,  0.000000)
(-0.000000,  0.000000,  1.000000)
(-0.212683, -0.977121,  0.000000)
( 0.000000,  0.000000, -1.000000)

N=6, min distance 1.414214
( 1.000000,  0.000000,  0.000000)
(-1.000000,  0.000000,  0.000000)
( 0.000000, -0.752754, -0.658302)
( 0.000000,  0.752754,  0.658302)
( 0.000000,  0.658302, -0.752754)
( 0.000000, -0.658302,  0.752754)

N=7, min distance 1.256870
( 1.000000,  0.000000,  0.000000)
(-0.688059, -0.725655,  0.000000)
( 0.210138, -0.488836, -0.846689)
( 0.210138, -0.488836,  0.846688)
(-0.688059,  0.362827,  0.628435)
(-0.688059,  0.362827, -0.628435)
( 0.210138,  0.977672,  0.000000)

N=8, min distance 1.215563
( 1.000000,  0.000000,  0.000000)
( 0.261204, -0.965284,  0.000000)
( 0.261204,  0.565450,  0.782329)
(-0.783612, -0.482642, -0.391165)
( 0.261204, -0.199917, -0.944355)
( 0.261204,  0.882475, -0.391165)
(-0.783612,  0.599750,  0.162026)
(-0.477592, -0.399834,  0.782329)

N=9, min distance 1.154701
( 1.000000,  0.000000,  0.000000)
(-0.500000, -0.866025,  0.000000)
( 0.333333, -0.577350, -0.745356)
(-0.500000,  0.866025,  0.000000)
(-0.666667, -0.000000,  0.745356)
(-0.666667,  0.000000, -0.745356)
( 0.333333, -0.577350,  0.745356)
( 0.333333,  0.577350, -0.745356)
( 0.333333,  0.577350,  0.745356)

N=10, min distance 1.091426
( 1.000000,  0.000000,  0.000000)
(-0.605995,  0.795469,  0.000000)
( 0.404394,  0.816443,  0.412172)
(-0.664045, -0.746251, -0.046407)
( 0.404394, -0.363508, -0.839242)
(-0.664045,  0.002497,  0.747688)
(-0.605995,  0.046721, -0.794096)
( 0.404394, -0.908368,  0.106452)
( 0.255933,  0.703344, -0.663179)
( 0.404394, -0.159620,  0.900548)

By looking at the numbers, it is obvious that some of the solutions could be computed analytically (I recognize sqrt(2) and sqrt(3), etc). I believe for N=2, 4 and 6 the solutions are straight line ([-1,0,0], [1,0,0]), tetrahedron, octahedron.

There is no strong guarantee that the above are the best possible distribution of the points. The nonlinear solver could have gotten stuck in a local optimum; as N grows, the number of local optima also grows.

You can just put the above solutions in an array and use them in Python, C++ or whatever language it is that you use.

Ali
  • 56,466
  • 29
  • 168
  • 265