#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

struct Facet 
  {
  int    Facetnum;
  struct Facet *left;
  struct Facet *right;
  double apex_x;
  double apex_y;
  double apex_z;
  char   POVobject[102400];
  };
struct Facet Facet01;
struct Facet Facet02;
struct Facet Facet03;
struct Facet Facet04a;
struct Facet Facet04b;
struct Facet Facet05;
struct Facet Facet06;
struct Facet Facet07;
struct Facet Facet08;
struct Facet Facet09;
struct Facet Facet10;
struct Facet Facet11;
struct Facet Facet12;
struct Facet Facet13a;
struct Facet Facet13b;
struct Facet Facet14;
struct Facet Facet15;
struct Facet Facet16;
struct Facet Facet17;
struct Facet Facet18;
struct Facet Facet19;
struct Facet Facet20;

int depth=0;

double arcsin(double sinvalue)
  {
  return(57.29578*asin(sinvalue));
  }
double arccos(double sinvalue)
  {
  return(57.29578*acos(sinvalue));
  }

void init_facets()
  {
  Facet05.left  = &Facet19;
  Facet05.right = &Facet06;
  Facet05.apex_x = 0;
  Facet05.apex_y = 0;
  Facet05.apex_z = 0;
  Facet05.Facetnum = 5;
  
  Facet19.left  = &Facet17;
  Facet19.right = &Facet01;
  Facet19.apex_x = 4.2518;
  Facet19.apex_y = -2.6311;
  Facet19.apex_z = 0;
  Facet19.Facetnum = 19;
  
  Facet17.left  = &Facet14;
  Facet17.right = &Facet15;
  Facet17.apex_x = 0;
  Facet17.apex_y = -4.2518;
  Facet17.apex_z = -2.6311;
  Facet17.Facetnum = 17;
  
  Facet14.left  = NULL;
  Facet14.right = NULL;
  Facet14.apex_x = 0;
  Facet14.apex_y = 0;
  Facet14.apex_z = 0;
  Facet14.Facetnum = 14;
  
  Facet15.left  = &Facet03;
  Facet15.right = NULL;
  Facet15.apex_x = 2.6235;
  Facet15.apex_y = 0;
  Facet15.apex_z = -4.2564;
  Facet15.Facetnum = 15;
  
  Facet03.left  = &Facet12;
  Facet03.right = &Facet04a;
  Facet03.apex_x = -2.6235;
  Facet03.apex_y = 0;
  Facet03.apex_z = -4.2564;
  Facet03.Facetnum = 3;
  
  Facet12.left  = NULL;
  Facet12.right = NULL;
  Facet12.apex_x = 0;
  Facet12.apex_y = 0;
  Facet12.apex_z = 0;
  Facet12.Facetnum = 12;
  
  Facet04a.left  = NULL;
  Facet04a.right = NULL;
  Facet04a.apex_x = 0;
  Facet04a.apex_y = 0;
  Facet04a.apex_z = 0;
  Facet04a.Facetnum = 40;
  
  Facet04b.left  = NULL;
  Facet04b.right = NULL;
  Facet04b.apex_x = 0;
  Facet04b.apex_y = 0;
  Facet04b.apex_z = 0;
  Facet04b.Facetnum = 41;
  
  Facet01.left  = &Facet07;
  Facet01.right = NULL;
  Facet01.apex_x = 4.2518;
  Facet01.apex_y = 2.6311;
  Facet01.apex_z = 0;
  Facet01.Facetnum = 1;
  
  Facet07.left  = NULL;
  Facet07.right = NULL;
  Facet07.apex_x = 0;
  Facet07.apex_y = 0;
  Facet07.apex_z = 0;
  Facet07.Facetnum = 7;
  
  Facet06.left  = &Facet09;
  Facet06.right = &Facet20;
  Facet06.apex_x = 0;
  Facet06.apex_y = 4.2518;
  Facet06.apex_z = 2.6311;
  Facet06.Facetnum = 6;
  
  Facet09.left  = NULL;
  Facet09.right = &Facet13a;
  Facet09.apex_x = 4.2518;
  Facet09.apex_y = 2.6311;
  Facet09.apex_z = 0;
  Facet09.Facetnum = 9;
  
  Facet20.left  = &Facet18;
  Facet20.right = &Facet02;
  Facet20.apex_x = -4.2518;
  Facet20.apex_y = 2.6311;
  Facet20.apex_z = 0;
  Facet20.Facetnum = 20;
  
  Facet18.left  = &Facet13b;
  Facet18.right = &Facet16;
  Facet18.apex_x = 0;
  Facet18.apex_y = 4.2518;
  Facet18.apex_z = -2.6311;
  Facet18.Facetnum = 18;
  
  Facet13a.left  = NULL;
  Facet13a.right = NULL;
  Facet13a.apex_x = 0;
  Facet13a.apex_y = 0;
  Facet13a.apex_z = 0;
  Facet13a.Facetnum = 130;
  
  Facet13b.left  = NULL;
  Facet13b.right = &Facet11;
  Facet13b.apex_x = 4.2518;
  Facet13b.apex_y = 2.6311;
  Facet13b.apex_z = 0;
  Facet13b.Facetnum = 131;
  
  Facet11.left  = NULL;
  Facet11.right = &Facet04b;
  Facet11.apex_x = 2.6235;
  Facet11.apex_y = 0;
  Facet11.apex_z = -4.2564;
  Facet11.Facetnum = 11;
  
  Facet16.left  = NULL;
  Facet16.right = NULL;
  Facet16.apex_x = 0;
  Facet16.apex_y = 0;
  Facet16.apex_z = 0;
  Facet16.Facetnum = 16;
  
  Facet02.left  = &Facet08;
  Facet02.right = &Facet10;
  Facet02.apex_x = -4.2518;
  Facet02.apex_y = -2.6311;
  Facet02.apex_z = 0;
  Facet02.Facetnum = 2;
  
  Facet08.left  = NULL;
  Facet08.right = NULL;
  Facet08.apex_x = 0;
  Facet08.apex_y = 0;
  Facet08.apex_z = 0;
  Facet08.Facetnum = 8;
  
  Facet10.left  = NULL;
  Facet10.right = NULL;
  Facet10.apex_x = 0;
  Facet10.apex_y = 0;
  Facet10.apex_z = 0;
  Facet10.Facetnum = 10;
  
  memset(Facet01.POVobject,0,sizeof(char));  
  memset(Facet02.POVobject,0,sizeof(char));  
  memset(Facet03.POVobject,0,sizeof(char));  
  memset(Facet04a.POVobject,0,sizeof(char));  
  memset(Facet04b.POVobject,0,sizeof(char));  
  memset(Facet05.POVobject,0,sizeof(char));  
  memset(Facet06.POVobject,0,sizeof(char));  
  memset(Facet07.POVobject,0,sizeof(char));  
  memset(Facet08.POVobject,0,sizeof(char));  
  memset(Facet09.POVobject,0,sizeof(char));  
  memset(Facet10.POVobject,0,sizeof(char));  
  memset(Facet11.POVobject,0,sizeof(char));  
  memset(Facet12.POVobject,0,sizeof(char));  
  memset(Facet13a.POVobject,0,sizeof(char));  
  memset(Facet13b.POVobject,0,sizeof(char));  
  memset(Facet14.POVobject,0,sizeof(char));  
  memset(Facet15.POVobject,0,sizeof(char));  
  memset(Facet16.POVobject,0,sizeof(char));  
  memset(Facet17.POVobject,0,sizeof(char));  
  memset(Facet18.POVobject,0,sizeof(char));  
  memset(Facet19.POVobject,0,sizeof(char));  
  memset(Facet20.POVobject,0,sizeof(char));  
  }

void pivot(struct Facet *Facet_number,
           double x1, double y1, double z1,
           double x2, double y2, double z2,
           double zrotate,
           double *a0, double *b0, double *c0)
  {
  double xm,ym,zm,xmm,ymm,zmm,x0,y0,z0,d1,d2,rz,rx,y0new;
  double a1,b1,c1;
  double a2,b2,c2;
  double a3,b3,c3;
  double a4,b4,c4;
  double a5,b5,c5;
  double a6,b6,c6;
  double zrotate2,signx,signz,signx0;
  double tmpd1,tmpd2;
  double current_angle,new_angle;
  double current_angle2,new_angle2;
  char POVtemp[1024];

  *a0 = Facet_number->apex_x;
  *b0 = Facet_number->apex_y;
  *c0 = Facet_number->apex_z;

  tmpd1 = sqrt((x1*x1)+(y1*y1)+(z1*z1));
  tmpd2 = sqrt((x2*x2)+(y2*y2)+(z2*z2));

  if(tmpd1>tmpd2)
    {
    xm = x2; ym = y2; zm = z2;
    x0 = x1; y0 = y1; z0 = z1;
    }
  if(tmpd1<tmpd2)
    {
    xm = x1; ym = y1; zm = z1;
    x0 = x2; y0 = y2; z0 = z2;
    }
  if(tmpd1==tmpd2)
    {
    if(x1<x2)
      {
      xm = x1; ym = y1; zm = z1;
      x0 = x2; y0 = y2; z0 = z2;
      }
    if(x1>x2)
      {
      xm = x2; ym = y2; zm = z2;
      x0 = x1; y0 = y1; z0 = z1;
      }
    if(x1==x2)
      {
      if(y1<y2)
        {
        xm = x1; ym = y1; zm = z1;
        x0 = x2; y0 = y2; z0 = z2;
        }
      if(y1>y2)
        {
        xm = x2; ym = y2; zm = z2;
        x0 = x1; y0 = y1; z0 = z1;
        }
      if(y1==y2)
        {
        if(z1<z2)
          {
          xm = x1; ym = y1; zm = z1;
          x0 = x2; y0 = y2; z0 = z2;
          }
        if(z1>z2)
          {
          xm = x2; ym = y2; zm = z2;
          x0 = x1; y0 = y1; z0 = z1;
          }
        }
      }
    }

  sprintf(POVtemp,"    translate <%f,%f,%f>\n",-xm,-ym,-zm);
  strcat(Facet_number->POVobject,POVtemp);

  x0 = x0-xm;
  y0 = y0-ym;
  z0 = z0-zm;
  a1 = *a0-xm;
  b1 = *b0-ym;
  c1 = *c0-zm;

  d1 = sqrt((x0*x0)+(y0*y0));
  current_angle = arcsin(fabs(y0)/d1);

  if((x0>=0)&&(y0>=0))
    rz = 90-current_angle;
  if((x0>=0)&&(y0<0))
    rz = 90+current_angle;
  if((x0<0)&&(y0<0))
    rz = 270-current_angle;
  if((x0<0)&&(y0>=0))
    rz = 270+current_angle;

  a2 = (a1*cos(-(PI/180)*rz))+(b1*sin(-(PI/180)*rz));
  b2 = (-a1*sin(-(PI/180)*rz))+(b1*cos(-(PI/180)*rz));

  sprintf(POVtemp,"    rotate z*%f\n",rz);
  strcat(Facet_number->POVobject,POVtemp);

  y0new = d1;
  d2 = sqrt((z0*z0)+(y0new*y0new));

  current_angle2 = arcsin(fabs(z0)/d2);

  if((y0new>=0)&&(z0>=0))
    rx = 90-arcsin(fabs(z0)/d2);
  if((y0new>=0)&&(z0<0))
    rx = 90+arcsin(fabs(z0)/d2);
  if((y0new<0)&&(z0<0))
    rx = 270-arcsin(fabs(z0)/d2);
  if((y0new<0)&&(z0>=0))
    rx = 270+arcsin(fabs(z0)/d2);

  b3 = (b2*cos(-(PI/180)*rx))+(c1*sin(-(PI/180)*rx));
  c2 = (-b2*sin(-(PI/180)*rx))+(c1*cos(-(PI/180)*rx));

  sprintf(POVtemp,"    rotate x*%f\n",rx);
  strcat(Facet_number->POVobject,POVtemp);

  sprintf(POVtemp,"    rotate z*%f\n",zrotate);
  strcat(Facet_number->POVobject,POVtemp);

  a3 = (a2*cos(-(PI/180)*zrotate)) + (b3*sin(-(PI/180)*zrotate));
  b4 = (-a2*sin(-(PI/180)*zrotate)) + (b3*cos(-(PI/180)*zrotate));

  sprintf(POVtemp,"    rotate x*%f\n",-rx);
  strcat(Facet_number->POVobject,POVtemp);

  b5 = (b4*cos((PI/180)*rx))+(c2*sin((PI/180)*rx));
  c3 = (-b4*sin((PI/180)*rx))+(c2*cos((PI/180)*rx));

  sprintf(POVtemp,"    rotate z*%f\n",-rz);
  strcat(Facet_number->POVobject,POVtemp);

  a4 = (a3*cos((PI/180)*rz))+(b5*sin((PI/180)*rz));
  b6 = (-a3*sin((PI/180)*rz))+(b5*cos((PI/180)*rz));

  sprintf(POVtemp,"    translate <%f,%f,%f>\n",xm,ym,zm);
  strcat(Facet_number->POVobject,POVtemp);

  *a0 = a4+xm;
  *b0 = b6+ym;
  *c0 = c3+zm;

  Facet_number->apex_x = *a0;
  Facet_number->apex_y = *b0;
  Facet_number->apex_z = *c0;
  }

void rpivot(struct Facet *Facet_number,
            double x1, double y1, double z1,
            double x2, double y2, double z2,
            double zrotate,
            int Calling_Facet)
{
double apex_x,apex_y,apex_z;

pivot(Facet_number,
      x1,y1,z1,
      x2,y2,z2,
      zrotate,
      &apex_x,&apex_y,&apex_z);
if(Facet_number->left)
  {
  rpivot(Facet_number->left,
          x1,y1,z1,
          x2,y2,z2,
          zrotate,
          Facet_number->Facetnum);
  }
if(Facet_number->right)
  {
  rpivot(Facet_number->right,
          x1,y1,z1,
          x2,y2,z2,
          zrotate,
          Facet_number->Facetnum);
  }
}

void pivot_r(struct Facet *Facet_number,
             double x1, double y1, double z1,
             double x2, double y2, double z2,
             double zrotate,
             int Calling_Facet)
{
double apex_x,apex_y,apex_z;

pivot(Facet_number,
      x1,y1,z1,
      x2,y2,z2,
      zrotate,
      &apex_x,&apex_y,&apex_z);

if(Facet_number->left)
  {
  rpivot(Facet_number->left,
         x1,y1,z1,
         x2,y2,z2,
         zrotate,
         Facet_number->Facetnum);
  if((Facet_number->left->Facetnum==17)||
     (Facet_number->left->Facetnum==15)||
     (Facet_number->left->Facetnum==18)||
     (Facet_number->left->Facetnum==9)||
     (Facet_number->left->Facetnum==3)||
     (Facet_number->left->Facetnum==11)||
     (Facet_number->left->Facetnum==7))
    pivot_r(Facet_number->left,
            x1,y1,z1,
            apex_x,apex_y,apex_z,
            -zrotate,
            Facet_number->Facetnum);
  else
    pivot_r(Facet_number->left,
            x1,y1,z1,
            apex_x,apex_y,apex_z,
            zrotate,
            Facet_number->Facetnum);
  }
if(Facet_number->right)
  {
  rpivot(Facet_number->right,
         x1,y1,z1,
         x2,y2,z2,
         zrotate,
         Facet_number->Facetnum);
  if((Facet_number->right->Facetnum==17)||
     (Facet_number->right->Facetnum==15)||
     (Facet_number->right->Facetnum==16)||
     (Facet_number->right->Facetnum==40)||
     (Facet_number->right->Facetnum==41)||
     (Facet_number->right->Facetnum==130)||
     (Facet_number->right->Facetnum==18))
    pivot_r(Facet_number->right,
            apex_x,apex_y,apex_z,
            x2,y2,z2,
            -zrotate,
            Facet_number->Facetnum);
  else
    pivot_r(Facet_number->right,
            apex_x,apex_y,apex_z,
            x2,y2,z2,
            zrotate,
            Facet_number->Facetnum);
  }
}

main()
{
int inc,j,plusfour;
char filename[16];
double zrotate,d,x,xcamera,ycamera,zcamera;
FILE *outf;

for(inc=-4;inc<32;inc++)
  {
  plusfour = inc+4;
  sprintf(filename,"dymax%03d.pov",plusfour);
  outf = fopen(filename,"w");
  printf("Outputting %s....\n",filename);
  if(inc>23)
    zrotate = 417.53905413413150427;
  else
    {
    switch(inc)
      {
      case -4:
        zrotate = 0;
        break;
      case -3:
        zrotate = 0.05;
        break;
      case -2:
        zrotate = 0.1;
        break;
      case -1:
        zrotate = 0.2;
        break;
      case 0:
        zrotate = 0.5;
        break;
      default:
        zrotate = pow(1.3,inc);
        break;
      }
    }
  x = 2.6142*zrotate;
  d = sqrt(pow((2.6325+x),2) + pow((4.2564+zrotate),2));

  xcamera = (0.1038961*plusfour)-8;  /* 8/77 */
  ycamera = (0.02525974*plusfour)+8; /* 1.2431/78 */
  zcamera = (0.23376623*plusfour)+8; /* 18/78 */

  fprintf(outf,"// Persistence of Vision Raytracer\n");
  fprintf(outf,"// Unfolding Dymaxion sphere\n");
  fprintf(outf,"#include \"colors.inc\"\n");
  fprintf(outf,"#include \"shapes.inc\"\n");
  fprintf(outf,"#include \"textures.inc\"\n");
  fprintf(outf,"\n");
  fprintf(outf,"// Camera\n");
  fprintf(outf,"camera {\n");
  fprintf(outf,"  location <%f,%f,%f> \n",xcamera,ycamera,zcamera);
  fprintf(outf,"  sky <-2.6235,0,4.2564>\n");
  fprintf(outf,"  look_at <0,0,0>\n");
  fprintf(outf,"  }\n");
  fprintf(outf,"\n");
  fprintf(outf,"// Light source\n");
  fprintf(outf,"light_source { <%f,%f,%f> color White }\n",xcamera,ycamera,zcamera);
  fprintf(outf,"\n");
  fprintf(outf,"#declare Facet = object {\n");
  fprintf(outf,"  sphere { <%f,0,%f>, %f }\n",-x,-zrotate,d);
  fprintf(outf,"  clipped_by { \n");
  fprintf(outf,"    plane { <0,0,-1>, 0 } \n");
  fprintf(outf,"    object { \n");
  fprintf(outf,"      plane { <0,0,-1>, 0 } \n");
  fprintf(outf,"      rotate x*-108\n");
  fprintf(outf,"      rotate z*-31.75\n");
  fprintf(outf,"      }\n");
  fprintf(outf,"    object { \n");
  fprintf(outf,"      plane { <0,0,-1>, 0 } \n");
  fprintf(outf,"      rotate x*108\n");
  fprintf(outf,"      rotate z*31.75\n");
  fprintf(outf,"      }\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  }\n");
  fprintf(outf,"\n");
  fprintf(outf,"#declare Globe = union {\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate x*90\n");
  fprintf(outf,"    rotate y*90\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate x*90\n");
  fprintf(outf,"    rotate y*90\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate x*90\n");
  fprintf(outf,"    rotate y*-90\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate x*90\n");
  fprintf(outf,"    rotate y*-90\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*180 \n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*180 \n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*396\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*396\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*252\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*252\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*324\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*324\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate x*108\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate x*108\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate x*396\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate x*396\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate x*324\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate x*324\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  }\n");
  fprintf(outf,"\n");
  fprintf(outf,"object {\n");
  fprintf(outf,"  Globe\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"  rotate z*180\n");
  fprintf(outf,"  }\n");
  fprintf(outf,"\n");
  fprintf(outf,"// EOF\n");
  fclose(outf);
  }

for(zrotate=01;zrotate<=42;zrotate++)
  {
  plusfour = inc+4;
  if(zrotate>0)
    zrotate = zrotate-0.0126;

  init_facets();
  pivot_r(&Facet19,0,-4.2518,2.6311,2.6235,0,4.2564,zrotate,5);
  pivot_r(&Facet06,2.6235,0,4.2564,-2.6235,0,4.2564,zrotate,5);

  sprintf(filename,"dymax%03d.pov",plusfour);
  outf = fopen(filename,"w");
  printf("Outputting %s....\n",filename);
  inc++;

  xcamera = (0.1038961*plusfour)-8;  /* 8/77 */
  ycamera = (0.02525974*plusfour)+8; /* 1.2431/78 */
  zcamera = (0.23376623*plusfour)+8; /* 18/78 */

  fprintf(outf,"// Persistence of Vision Raytracer\n");
  fprintf(outf,"// Unfolding Dymaxion sphere\n");
  fprintf(outf,"\n");
  fprintf(outf,"#include \"colors.inc\"\n");
  fprintf(outf,"#include \"shapes.inc\"\n");
  fprintf(outf,"#include \"textures.inc\"\n");
  fprintf(outf,"\n");
  fprintf(outf,"// Camera\n");
  fprintf(outf,"camera {\n");
  fprintf(outf,"  location <%f,%f,%f> \n",xcamera,ycamera,zcamera);
  fprintf(outf,"  sky <-2.6235,0,4.2564>\n");
  fprintf(outf,"  look_at <0,0,0>\n");
  fprintf(outf,"  }\n");
  fprintf(outf,"\n");
  fprintf(outf,"// Light source\n");
  fprintf(outf,"light_source { <%f,%f,%f> color White }\n",xcamera,ycamera,zcamera);
  fprintf(outf,"\n");
  fprintf(outf,"#declare Facet = object {\n");
  fprintf(outf,"  sphere { <-1087.3552047761052108,0,-417.53905413413150427>, 1168.7895460684055706 }\n");
  fprintf(outf,"  clipped_by { \n");
  fprintf(outf,"    plane { <0,0,-1>, 0 } \n");
  fprintf(outf,"    object { \n");
  fprintf(outf,"      plane { <0,0,-1>, 0 } \n");
  fprintf(outf,"      rotate x*-108\n");
  fprintf(outf,"      rotate z*-31.75\n");
  fprintf(outf,"      }\n");
  fprintf(outf,"    object { \n");
  fprintf(outf,"      plane { <0,0,-1>, 0 } \n");
  fprintf(outf,"      rotate x*108\n");
  fprintf(outf,"      rotate z*31.75\n");
  fprintf(outf,"      }\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  }\n");
  fprintf(outf,"\n");
  fprintf(outf,"#declare Facet04a = object {\n");
  fprintf(outf,"  Facet\n");
  fprintf(outf,"  clipped_by {\n");
  fprintf(outf,"    object {\n");
  fprintf(outf,"      plane { <0,0,1>, 0 }\n");
  fprintf(outf,"      rotate x*-30\n");
  fprintf(outf,"      rotate z*31.75\n");
  fprintf(outf,"      }\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  }\n");
  fprintf(outf,"#declare Facet04b = object {\n");
  fprintf(outf,"  Facet\n");
  fprintf(outf,"  clipped_by {\n");
  fprintf(outf,"    object {\n");
  fprintf(outf,"      plane { <0,0,-1>, 0 }\n");
  fprintf(outf,"      rotate x*-30\n");
  fprintf(outf,"      rotate z*31.75\n");
  fprintf(outf,"      }\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  }\n");
  fprintf(outf,"#declare Bound = intersection {\n");
  fprintf(outf,"    plane { <0,1,0>, 0 }\n");
  fprintf(outf,"    object {\n");
  fprintf(outf,"      plane { <0,0,-1>, 0 }\n");
  fprintf(outf,"      rotate x*30\n");
  fprintf(outf,"      rotate z*-31.75\n");
  fprintf(outf,"      }\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"#declare Facet13a = object {\n");
  fprintf(outf,"  Facet\n");
  fprintf(outf,"  clipped_by {\n");
  fprintf(outf,"    object { Bound }\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"  }\n");
  fprintf(outf,"#declare Facet13b = difference {\n");
  fprintf(outf,"  object { Facet }\n");
  fprintf(outf,"  object { Bound }\n");
  fprintf(outf,"  sphere { <-1087.3552047761052108,0,-417.53905413413150427>, 1168.7895460684055706\n");
  fprintf(outf,"  }\n");
  fprintf(outf,"    }\n");
  fprintf(outf,"#declare Globe = union {\n");
  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 01\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet01.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 02\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet02.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 03\n");
  fprintf(outf,"    rotate x*90\n");
  fprintf(outf,"    rotate y*90\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet03.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet04a // Facet 04a\n");
  fprintf(outf,"    rotate x*90\n");
  fprintf(outf,"    rotate y*90\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet04a.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet04b // Facet 04b\n");
  fprintf(outf,"    rotate x*90\n");
  fprintf(outf,"    rotate y*90\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet04b.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 05\n");
  fprintf(outf,"    rotate x*90\n");
  fprintf(outf,"    rotate y*-90\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet05.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 06\n");
  fprintf(outf,"    rotate x*90\n");
  fprintf(outf,"    rotate y*-90\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet06.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 07\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*180\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet07.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 08\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*180\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet08.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 09\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*396\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet09.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 10\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*396\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet10.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 11\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*252\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet11.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 12\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*252\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet12.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet13a // Facet 13a\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*324\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet13a.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet13b // Facet 13b\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*324\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet13b.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 14\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate x*324\n");
  fprintf(outf,"    rotate z*31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet14.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 15\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate x*108\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet15.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 16\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate x*108\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet16.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 17\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate x*396\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet17.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 18\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate x*396\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet18.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 19\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate x*324\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet19.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  object {\n");
  fprintf(outf,"    Facet // Facet 20\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate x*324\n");
  fprintf(outf,"    rotate z*-31.75\n");
  fprintf(outf,"    rotate z*180\n");
  fprintf(outf,"    pigment {image_map { tga \"clearmap.tga\" map_type 1 interpolate 2 }\n");
  fprintf(outf,"             rotate x*80 rotate z*31 rotate y*5 }\n");
  
  fprintf(outf,"    finish {ambient 0.5}\n");
  fprintf(outf,"%s",Facet20.POVobject);
  fprintf(outf,"    }\n");

  fprintf(outf,"  }\n");
  fprintf(outf,"\n");
  fprintf(outf,"object {\n");
  fprintf(outf,"  Globe\n");
  fprintf(outf,"  rotate z*180\n");
  fprintf(outf,"  }\n");

  fclose(outf);

  if(zrotate>0)
    zrotate = zrotate+0.0126;
  }
}

