// gyroid-tri.fe

// Gyroid by Bonnet rotation of triangular chunk of D surface,
//   one-sixth of the hexagon in gyroid1.fe.
// After loading, this file will automatically evolve the D surface,
//   do the Bonnet rotation, and show multiple transforms.
// The user can experiment with the transform_expr command to show
// various size pieces of the gyroid.  For increasing amounts, try
//    transform_expr "aaabbbccc"
//    transform_expr "abcabcabc"
// Due to lack of suitable boundary conditions, the surface is not 
// evolvable after doing the Bonnet rotation.

// replication transformations for gyroid
// Rotations and inversions about normal vectors, which are
// invariant for Bonnet rotations (except axes translated).

// for diagonals of the hexagon of D 
constraint 1 
formula: y = z

constraint 2
formula: x = y

parameter atrans1 = 2
parameter atrans2 = 0
parameter atrans3 = 0

parameter btrans1 = 0
parameter btrans2 = 2
parameter btrans3 = 0

parameter ctrans1 = 1
parameter ctrans2 = 1
parameter ctrans3 = 1

view_transform_generators 3

// 4-fold rotoinversion through vertex 1
// 90 degree rotation about x axis with x inversion
swap_colors
-1 0 0 atrans1
 0 0 1 atrans2 
 0 -1 0 atrans3
 0 0 0 1

// 4-fold rotoinversion through vertex 2
// 90 degree rotation about z axis with z inversion
swap_colors
0 1 0 btrans1
-1 0 0 btrans2
 0 0 -1 btrans3
 0 0 0 1

// 6-fold rotoinversion through vertex 3
// 60 degree rotation about (1,1,1) axis with inversion
swap_colors
 0 -1 0 ctrans1
 0  0 -1 ctrans2 
 -1 0 0 ctrans3
 0 0 0 1

// data for D surface patch
vertices
1   1 0 0 fixed
2   1 1 0 fixed
3   0.5 0.5 0.5 fixed

edges
1   1 2 fixed
2   2 3 constraint 2
3   3 1 constraint 1

faces
1   1 2 3   frontcolor white backcolor yellow

read

read "adjoint.cmd"

// Evolve D surface
gogoD := { r; g 5; r; g 5; hessian; r; g 5; hessian; }

bangle :=  38.015

// Do Bonnet rotation
bonnet := { 
  unfix vertex;
  unfix edge;
  unset vertex constraint 1;
  unset edge constraint 1;
  unset vertex constraint 2;
  unset edge constraint 2;
  adjoint;
  xmid := vertex[3].x;
  ymid := vertex[3].y;
  zmid := vertex[3].z;
  set vertex x x-xmid;
  set vertex y y-ymid;
  set vertex z z-zmid;

  // fix up view transform generators

  atrans1 := 2*vertex[1].x;
  atrans2 := vertex[1].y - vertex[1].z;
  atrans3 := vertex[1].z + vertex[1].y;

  btrans1 := vertex[2].x - vertex[2].y; 
  btrans2 := vertex[2].y + vertex[2].x;
  btrans3 := 2*vertex[2].z;

  ctrans1 := 0;
  ctrans2 := 0;
  ctrans3 := 0;

  // redefine 'g'and stuff so user doesn't accidently try to evolve
  g :::= { printf 
     "This gyroid is not evolvable due to lack of boundary constraints.\n"; 
  };
  r :::= { printf 
     "This gyroid is not evolvable due to lack of boundary constraints.\n"; 
  };
  u :::= { printf 
     "This gyroid is not evolvable due to lack of boundary constraints.\n"; 
  };
  V :::= { printf 
     "This gyroid is not evolvable due to lack of boundary constraints.\n"; 
  };

  show_trans "m"; 
  show_trans "mzz"; 
}

gogoD;
bonnet;
thickness /= 2;  // needs a little boost so backside color doesn't show



