#define PROG_NAME "MakePolytope" #define PROG_DESC "???" #define PROG_VERS "1.0" /* Last edited on 2024-12-21 11:32:47 by stolfi */ #define MakePolytope_C_COPYRIGHT \ "" #define PROG_INFO \ "" \ " " /* This program generates the topology of 4D regular and convex polytopes (".tp" files) with fixed ("-fix") or random ("-ran") geometry. */ #define MakePolytope_C_author \ "Implemented by L.A.P.Lozada, 1999-2000.\n" \ "Modified by L.A.P.Lozada on 2000-02-10." #include #include #include #include #include #include #include #include TYPE double Shape_t = {cell5, cell8, cell16}; typedef struct Options_t { Shape_t shape; char *shapeName; bool_t random; /* TRUE if it geometry is random. */ bool_t polyroot; /* includes the cell root information */ } CONST double order = 1; Options_t *GetOptions(int argc, char **argv); int main(int argc, char **argv) Coords_t c; char *tag; { Options_t *o = GetOptions(argc, argv); char *topo_cmt = jsprintf("Created by %s on %s", PROG_NAME, Today()); /* Random_t coins = MakeRandomSource(4615); */ ??? ran = o->random; ??? m = MakePolytope(o->shape); ??? top = MakeElemTable(m); { c = r4_vec_new(top.node.nel); /* seting the elements root for edges and walls.*/ for (i = 0; i < top.wall.nel; i++) { Wall_t f = top.wall.el[i]; f->root = f->num; } for (i = 0; i < top.edge.nel; i++) { Edge_t e = top.edge.el[i]; e->root = e->num; } if (! ran ){ c = FixCoords(top, o->shape, m); tag ="-fix"; WriteTopology( o->shapeName & tag, top, "Created by MakePolytope: " & o->shapeName & "-fix.tp on " \ Today() ); WriteState( o->shapeName & tag,top, c^, "Created by MakePolytope: " & o->shapeName & "-fix.st on " \ Today() ); WriteMaterials( o->shapeName & tag, top, "Created by MakePolytope: " & o->shapeName & "-fix.ma on " \ Today() ); } else { c = GenCoords(top); tag ="-r"; WriteTopology( o->shapeName & tag, top, "Created by MakePolytope: " & o->shapeName & "-r.tp on " \ Today() ); WriteState( o->shapeName & tag,top, c^, "Created by MakePolytope: " & o->shapeName & "-r.st on " \ Today() & "\nRandom Geometry" ); if (! o->polyroot) { WriteMaterials( o->shapeName & tag, top, "Created by MakePolytope: " & o->shapeName & "-r.ma on " \ Today(), FALSE); } else if (o->polyroot){ for (i = 0; i < top.cell.nel; i++) { ??? p = top.cell[i]; { p->root = p->num; } } WriteMaterials( o->shapeName & tag, top, "Created by MakePolytope: " & o->shapeName & "-r.ma on " \ Today(), TRUE); } } return 0; } Place_t MakePolytope(Shape_t shape) { CASE shape OF break; case Shape_cell5: return MakeHypertetrahedron(); break; case Shape_cell8: return MakeHypercube(); break; case Shape_cell16: return MakeHyperoctahedron(); } } /* END MakePolytope */ /* Shape builders: */ Place_t MakeHypertetrahedron() /* Glue five tetrahedra. The Hypertetrahedron is one polytope that corresponding to analogus 4-D of one 3-simplex. This 4-simplex have C5,0 nodes, C5,1 edegs, C5,2 walls and C5,3 cells. */ { ??? o = order; ??? a = MakeTetraTopo(o; with (o), double b = MakeTetraTopo(o,o); double c = MakeTetraTopo(o,o); double d = MakeTetraTopo(o,o); double e = MakeTetraTopo(o,o) ){ Glue(Spin(b[1]), a[0],o); /* a-b, 0-1 */ Glue(Spin(a[1]), c[0],o); /* a-c, 0-2 */ Glue(Spin(c[1]), b[0],o); /* b-c, 1-2 */ Glue(Spin(a[3]), e[2],o); /* a-e, */ Glue(Clock(a[2]),d[2],o); /* a-d */ Glue(Clock(d[3]),e[3],o); /* d-e */ Glue(Spin(PrevE(d[0])),NextE(c[2]),o); /* c-d */ Glue(Clock(PrevE(b[2])),PrevE(d[1]),o); /* d-b */ Glue(Spin(PrevE(e[1])),NextE(c[3]),o); /* e-c */ Glue(Clock(PrevE(b[3])),PrevE(e[0]),o); /* e-b */ fprintf(stderr, "Building topology of 5-cell:\n"); return b[1]; } } /* END MakeHypertetrahedron */ Place_t MakeHyperoctahedron() /* Glue 16 tetrahedra. The Hyperoctahedron is one polytope that corresponding to analogus 4-D of one octahedron. This politope is the dual of the hipercube, so has 8 nodes, 24 @{edge->?}s, 32 walls and 16 tetraedra. */ { ??? o = 4; ??? a = MakeTetraTopo(o; with (o) ){ Glue(Spin(a[1]),a[0],o); Glue(Spin(a[3]),a[2],o); fprintf(stderr, "Building topology of Hyperoctahedron:\n"); return a[1]; } } /* END MakeHyperoctahedron */ Place_t MakeHypercube() /* Glue eight cubes. The Hypercube is one polytope that corresponding to analogus 4-D of one cube. This polytope have "16" nodes, "32" @{edge->?}s, "24" walls, "96" wedges and "8" cells. */ { ??? ca = CubeLAPLMake(); ??? cb = CubeLAPLMake(); ??? cc = CubeLAPLMake(); ??? cd = CubeLAPLMake(); ??? ce = CubeLAPLMake(); ??? cf = CubeLAPLMake(); ??? cg = CubeLAPLMake(); ??? ch = CubeLAPLMake(); { /* step one */ GlueCube(ca.el[1], PrevF(cb.el[2])); /* 1, a-b */ GlueCube(ca.el[2], PrevF(cc.el[3])); /* 2, a-c */ GlueCube(ca.el[3], PrevF(cd[4])); /* 3, a-d */ GlueCube(ca.el[4], PrevF(ce[1])); /* 4, a-e */ GlueCube(ca.el[5], Clock(cf[0])); /* 5, a-f */ GlueCube(ca.el[0], Clock(cg[5])); /* 6, a-g */ GlueCube(cg[0], Clock(ch[5])); /* 7, g-h */ /* step two */ GlueCube(cb.el[2], PrevF(cc.el[4])); /* 8, b-c */ GlueCube(cc.el[3], PrevF(cd[1])); /* 9, c-d */ GlueCube(cd[4], PrevF(ce[2])); /* 10, d-e */ GlueCube(ce[1], PrevF(cb.el[3])); /* 11, e-b */ GlueCube(NextE(cb.el[5]), Clock(PrevE(cf[1]))); /* 12, f-b */ GlueCube(ce[5], Clock(PrevE(cf[4]))); /* 13, f-e */ GlueCube(NextE(NextE(cc.el[5])), PrevF(cf[0])); /* 14, f-c */ GlueCube(PrevE(cf[3]), Clock(PrevE(cd[5]))); /* 15, f-d */ GlueCube(PrevE(cb.el[0]), Clock(NextE(cg[1]))); /* 16, b-g */ GlueCube(ce[0], Clock(NextE(cg[4]))); /* 17, e-g */ GlueCube(NextE(cg[3]), Clock(NextE(cd[0]))); /* 18, d-g */ GlueCube(NextE(cg[2]),Clock(PrevE(PrevE(cc.el[0]))));/* 19, c-g */ /* step three */ GlueCube(cb.el[1], Clock(ch[1])); /* 20, b-h */ GlueCube(ch[2], Clock(cc.el[2])); /* 21, c-h */ GlueCube(PrevE(cd[3]), Clock(NextE(ch[3]))); /* 22, d-h */ GlueCube(PrevE(ce[4]), Clock(NextE(ch[4]))); /* 23, e-h */ GlueCube(cf[5],Clock(ch[0])); /* 24, f-h */ fprintf(stderr, "Building topology of 8-cell:\n"); return ch[0]; } } /* END MakeHypercube */ /* UNUSED */ Place_t Make24tetra() a : ARRAY[0..23] OF ARRAY[0..7] OF Place_t; { for (i = 0; i <= (23); i++){ a[i] = MakeTetraTopo(order,order); } /* first level */ Glue(Spin(a[1][1]),a[0][0],order); Glue(Spin(a[2][1]),a[1][0],order); Glue(Spin(a[3][1]),a[2][0],order); Glue(Spin(a[4][1]),a[3][0],order); Glue(Spin(a[5][1]),a[4][0],order); Glue(Spin(a[0][1]),a[5][0],order); /* next level */ Glue(Spin(a[0][3]),a[6][2],order); Glue(Spin(a[1][3]),a[7][2],order); Glue(Spin(a[2][3]),a[8][2],order); Glue(Spin(a[3][3]),a[9][2],order); Glue(Spin(a[4][3]),a[10][2],order); Glue(Spin(a[5][3]),a[11][2],order); Glue(Spin(a[12][1]),a[6][0],order); Glue(Spin(a[7][1]),PrevE(a[12][7]),order); Glue(Spin(a[13][1]),a[7][0],order); Glue(Spin(a[8][1]),PrevE(a[13][7]),order); Glue(Spin(a[14][1]),a[8][0],order); Glue(Spin(a[9][1]),PrevE(a[14][7]),order); Glue(Spin(a[15][1]),a[9][0],order); Glue(Spin(a[10][1]),PrevE(a[15][7]),order); Glue(Spin(a[16][1]),a[10][0],order); Glue(Spin(a[11][1]),PrevE(a[16][7]),order); Glue(Spin(a[17][1]),a[11][0],order); Glue(Spin(a[6][1]),PrevE(a[17][7]),order); /* Last level */ Glue(Spin(NextE(a[12][0])),a[18][2],order); Glue(Spin(NextE(a[13][0])),a[19][2],order); Glue(Spin(NextE(a[14][0])),a[20][2],order); Glue(Spin(NextE(a[15][0])),a[21][2],order); Glue(Spin(NextE(a[16][0])),a[22][2],order); Glue(Spin(NextE(a[17][0])),a[23][2],order); Glue(Spin(a[19][1]),a[18][0],order); Glue(Spin(a[20][1]),a[19][0],order); Glue(Spin(a[21][1]),a[20][0],order); Glue(Spin(a[22][1]),a[21][0],order); Glue(Spin(a[23][1]),a[22][0],order); Glue(Spin(a[18][1]),a[23][0],order); fprintf(stderr, "Building topology of Icosahedron: \n"); return a[0][1]; } /* END Make24tetra */ Coords_t *FixCoordsHypercube( Place_t *h; *ElemTableRec_t *top; )== { ??? r = NEW(REF Coords_t; with ( top->node.nel), double c = r^; double o1 = (r4_t){ 1.0, 1.0, 1.0,1.0}; double o2 = (r4_t){ 1.0, 1.0,-1.0,1.0}; double o3 = (r4_t){ 1.0,-1.0, 1.0,1.0}; double o4 = (r4_t){ 1.0,-1.0,-1.0,1.0}; double o5 = (r4_t){-1.0, 1.0, 1.0,1.0}; double o6 = (r4_t){-1.0, 1.0,-1.0,1.0}; double o7 = (r4_t){-1.0,-1.0, 1.0,1.0}; double o8 = (r4_t){-1.0,-1.0,-1.0,1.0}; double o9 = (r4_t){ 1.0, 1.0, 1.0,-1.0}; o10== (r4_t){ 1.0, 1.0,-1.0,-1.0}, o11== (r4_t){ 1.0,-1.0, 1.0,-1.0}, o12== (r4_t){ 1.0,-1.0,-1.0,-1.0}, o13== (r4_t){-1.0, 1.0, 1.0,-1.0}, o14== (r4_t){-1.0, 1.0,-1.0,-1.0}, o15== (r4_t){-1.0,-1.0, 1.0,-1.0}, o16== (r4_t){-1.0,-1.0,-1.0,-1.0} ){ void SetCoCoords(Place_t e, r4_t *cv) { c[OrgV(e)->num] = cv; } SetCoCoords; { /* Set the corners */ SetCoCoords(h,o13); SetCoCoords(PrevE(h),o15); SetCoCoords(PrevE(PrevE(h)),o11); SetCoCoords(Clock(h),o9); SetCoCoords(PrevE(PrevF(h)),o14); SetCoCoords(PrevE(PrevE(PrevF(h))),o10); SetCoCoords(PrevE(PrevF(PrevE(PrevE(h)))),o12); SetCoCoords(PrevE(PrevE(PrevF(PrevE(PrevE(h))))),o16); SetCoCoords(PrevE(NextF(h)),o5); SetCoCoords(NextE(NextE(NextF(h))),o1); SetCoCoords(PrevE(NextF(PrevE(PrevE(h)))),o3); SetCoCoords(PrevE(PrevE(NextF(PrevE(PrevE(h))))),o7); SetCoCoords(PrevE(PrevF(PrevE(PrevE(PrevF(h))))),o2); SetCoCoords(PrevE(PrevE(PrevF(PrevE(PrevE(PrevF(h)))))), o6); SetCoCoords(PrevE(PrevF(PrevE(PrevE(PrevF(PrevE(PrevE (h))))))),o8); SetCoCoords(PrevE(PrevE(PrevF(PrevE(PrevE(PrevF(PrevE (PrevE(h)))))))),o4); } return r; } } /* END FixCoordsHypercube */ PROCEDURE FixCoordsHypertetrahedron( /* UNUSED */ *h: Place_t; *ElemTableRec_t *top; ): REF Coords_t { ??? r = NEW(REF Coords_t; with ( top->node.nel), double c = r^; double c0 = (r4_t){0.0, 0.0, 0.0, 2.0}; double c1 = (r4_t){-1.118030, 1.118030, 1.118030, -0.50}; double c2 = (r4_t){ 1.118030, -1.118030, 1.118030, -0.50}; double c3 = (r4_t){ 1.118030, 1.118030, -1.118030, -0.50}; double c4 = (r4_t){-1.118030, -1.118030, -1.118030, -0.50} ){ c[0] = c0; c[1] = c1; c[2] = c2; c[3] = c3; c[4] = c4; return r; } } /* END FixCoordsHypertetrahedron */ PROCEDURE FixCoordsHyperoctahedron( /* UNUSED */ *h: Place_t; *ElemTableRec_t *top; ): REF Coords_t { ??? r = NEW(REF Coords_t; with ( top->node.nel), double c = r^; double c0 = (r4_t){ 0.0, -2.0, 0.0, 0.0}; double c1 = (r4_t){ 0.0, 0.0, -2.0, 0.0}; double c2 = (r4_t){ 2.0, 0.0, 0.0, 0.0}; double c3 = (r4_t){ 0.0, 0.0, 0.0,-2.0}; double c4 = (r4_t){ 0.0, 0.0, 2.0, 0.0}; double c5 = (r4_t){ 0.0, 0.0, 0.0, 2.0}; double c6 = (r4_t){-2.0, 0.0, 0.0, 0.0}; double c7 = (r4_t){ 0.0, 2.0, 0.0, 0.0} ){ c[0] = c0; c[1] = c1; c[2] = c2; c[3] = c3; c[4] = c4; c[5] = c5; c[6] = c6; c[7] = c7; return r; } } /* END FixCoordsHyperoctahedron */ Coords_t *FixCoords(ElemTableRec_t *top, shape:Shape_t; *m : Place_t)== { ??? r = NEW(REF Coords_t; with ( top->node.nel), double c = r^ ){ if (shape == Shape_cell5 ){ /* Atribui coordenadas fixas no R4, t. q. o comprimento de toda aresta \'e 1.5811. */ c = FixCoordsHypertetrahedron(m,top)^; } else if ( shape == Shape_cell8){ /* Atribui coordenadas fixas no R4, t. q. o comprimento de toda aresta \'e 2.00. */ c = FixCoordsHypercube(m,top)^; } else if ( shape == Shape_cell16){ /* Atribui coordenadas fixas no R4. */ c = FixCoordsHyperoctahedron(m,top)^; } return r; } } /* END FixCoords */ Options_t GetOptions () { Options_t *o = (Options_t *)malloc(sizeof(Options_t)); argparser_t *pp = argparser_new(stderr, argc, argv); argparser_set_help(pp, PROG_NAME " version " PROG_VERS ", usage:\n" PROG_HELP); argparser_set_info(pp, PROG_INFO); argparser_process_help_info_options(pp); argparser_get_keyword(pp, "-shape"); o->shapeName = argparser_get_next(pp); if (0 == strcmp(o->shapeName, "5cell"))) { o->shape = Shape_cell5 } else if (0 == strcmp(o->shapeName, "8cell"))){ o->shape = Shape_cell8 } else if (0 == strcmp(o->shapeName, "16cell"))){ o->shape = Shape_cell16 } else { argparser_error(pp, "Bad shape \"" & argparser_get_next(pp) & "\"\n") } o->random = argparser_keyword_present(pp, "-random"); o->polyroot = argparser_keyword_present(pp, "-polyroot"); argparser_finish(pp); ----------------------------------- #define _HELP \ fprintf(stderr, "Usage: MakePolytope \\\n" \ " -shape { 5cell | 8cell | 16cell ... } \\\n" \ " [ -random ] [-polyroot]\n"); END¦ } } return o; } /* END GetOptions */ /* end MakePolytope */ /* Copyright © 2001 Universidade Estadual de Campinas (UNICAMP) */