2 * We try to find an optimal triangle grid
4 * Vertices in strip are numbered as follows:
6 * ___ L-2 ___ L-1 ___ 0 ___ 1 ___ 2 ___ 3 ___ 4 __
8 * / \ / \ / \ / \ / \ / \ / \
9 * / \ / \ / \ / \ / \ / \ / \
10 * L-3 ___ L-2 ___ L-1 ___ 0 ___ 1 ___ 2 ___ 3 ___ 4
11 * W-2 W-2 W-2 1 1 1 1 1
12 * \ / \ / \ / \ / \ / \ / \ /
13 * \ / \ / \ / \ / \ / \ / \ /
14 * ___ L-3 ___ L-2 ___ L-1 ___ 0 ___ 1 ___ 2 ___ 3 __
16 * / \ / \ / \ / \ / \ / \ / \
17 * / \ / \ / \ / \ / \ / \ / \
18 * . . . . . . . . . . . . . . . .
20 * _ L-4 ___ L-3 ___ L-2 ___ L-1 ___ 0 ___ 1 ___ 2 ___ 3
21 * 1 1 1 1 W-2 W-2 W-2 W-2
22 * / \ / \ / \ / \ / \ / \ / \ /
23 * / \ / \ / \ / \ / \ / \ / \ /
24 * L-5 ___ L-4 ___ L-3 ___ L-2 ___ L-1 ___ 0 ___ 1 ___ 2 __
25 * 0 0 0 0 0 W-1 W-1 W-1
28 * 0 <= x < L x = distance along L = length
29 * 0 <= y < W y = distance across W = width
31 * Vertices are in reading order from diagram above ie x varies fastest.
33 * Where necessary, edges are counted anticlockwise from to-the-right:
42 * When we iterate over edges, we iterate first over vertices and then
43 * over edges 0 to 2, disregarding edges 3 to 5.
50 static double energy_function(const double vertices[N][3]) {
51 /* Energy has the following parts right now:
54 * Edgewise expected vertex displacement
71 * Find R', the `expected' location of R, by
72 * reflecting S in M (the midpoint of QP).
78 * Giving energy contribution:
85 * By symmetry, this calculation gives the same answer
86 * with R and S exchanged. Looking at the projection in
93 * R' ,' d" = |SS'| = |RR'| = d
104 * We choose this value for l (rather than |RM|+|MS|, say, or |RM|)
105 * because we want this symmetry and because we're happy to punish
106 * bending more than uneveness in the metric.
108 * In practice to avoid division by zero we'll add epsilon to l and
109 * the huge energy ought then to be sufficient for the model to
110 * avoid being close to R=S.
113 static gsl_multimin_fminimizer *minimiser;
118 gsl_multimin_fminimizer_alloc(