/* Create a triangular facet approximation to a sphere Return the number of facets created. The number of facets will be (4^iterations) * 8 */ int CreateNSphere(FACET3 *f,int iterations) { int i,it; double a; XYZ p[6] = {0,0,1, 0,0,-1, -1,-1,0, 1,-1,0, 1,1,0, -1,1,0}; XYZ pa,pb,pc; int nt = 0,ntold; /* Create the level 0 object */ a = 1 / sqrt(2.0); for (i=0;i<6;i++) { p[i].x *= a; p[i].y *= a; } f[0].p1 = p[0]; f[0].p2 = p[3]; f[0].p3 = p[4]; f[1].p1 = p[0]; f[1].p2 = p[4]; f[1].p3 = p[5]; f[2].p1 = p[0]; f[2].p2 = p[5]; f[2].p3 = p[2]; f[3].p1 = p[0]; f[3].p2 = p[2]; f[3].p3 = p[3]; f[4].p1 = p[1]; f[4].p2 = p[4]; f[4].p3 = p[3]; f[5].p1 = p[1]; f[5].p2 = p[5]; f[5].p3 = p[4]; f[6].p1 = p[1]; f[6].p2 = p[2]; f[6].p3 = p[5]; f[7].p1 = p[1]; f[7].p2 = p[3]; f[7].p3 = p[2]; nt = 8; if (iterations < 1) return(nt); /* Bisect each edge and move to the surface of a unit sphere */ for (it=0;it