#include #include #include extern const char *__progname; typedef struct pt PT; typedef struct tri TRI; struct pt { double x; double y; double z; } ; #define MAKEPT(xv,yv,zv) ((PT){.x=(xv),.y=(yv),.z=(zv)}) struct tri { int px[3]; } ; static double cos36; static double sin36; static int inters; static int npt; static PT *pts; static int nextpt; static int ntri; static TRI *tris; static int nexttri; static int *mesh; static int lines[12][12][2]; static double sqr(double x) { return(x*x); } static double dist(double d) { double x1; double z1; double x2; double y2; double z2; x1 = sqrt(1-sqr(d)); z1 = d; x2 = x1 * cos36; y2 = x1 * sin36; z2 = -d; return((sqr(x1)+sqr(1-z1)) - (sqr(x2-x1)+sqr(y2)+sqr(z2-z1))); } static double solve(double (*fn)(double), double l, double h) { double m; double f; if (((*fn)(l) < 0) && ((*fn)(h) > 0)) { } else if (((*fn)(l) > 0) && ((*fn)(h) < 0)) { m = l; l = h; h = m; } else { fprintf(stderr,"invalid solve\n"); exit(1); } while (1) { m = (h + l) / 2; if ((m == l) || (m == h)) return(m); f = (*fn)(m); if (f == 0) return(m); if (f < 0) l = m; else h = m; } } static PT epszero(PT p) { if (fabs(p.x) < 1e-10) p.x = 0; if (fabs(p.y) < 1e-10) p.y = 0; if (fabs(p.z) < 1e-10) p.z = 0; return(p); } static void setpt(int inx, PT p) { p = epszero(p); pts[inx] = p; } static double interp1(double a, double f, double b) { return((a*(1-f))+(b*f)); } static PT interp3(PT a, double f, PT b) { return(MAKEPT(interp1(a.x,f,b.x),interp1(a.y,f,b.y),interp1(a.z,f,b.z))); } static PT smul3(double f, PT p) { return(MAKEPT(p.x*f,p.y*f,p.z*f)); } static double norm(PT p) { return(sqrt((p.x*p.x)+(p.y*p.y)+(p.z*p.z))); } static PT unit(PT v) { return(smul3(1/norm(v),v)); } static void makeline(int a, int b) { int i; if (inters < 1) return; if (lines[a][b][0] < 0) { lines[a][b][0] = nextpt; lines[a][b][1] = 1; lines[b][a][0] = nextpt + inters - 1; lines[b][a][1] = -1; for (i=0;i= 2) { for (i=0;i