/* See {Pyramid.h} */ #include /* Last edited on 2007-02-04 16:17:37 by stolfi */ #define Pyramid_C_COPYRIGHT \ "Copyright © 2000,2007 Universidade Estadual de Campinas (UNICAMP)" #include #include #include #include #include #include #include #include #include #include #include #include Place_vec_t MakePyramid(uint n) { Place_t t[n]; Place_vec_t b = PolygonMake(n, TRUE, TRUE, TRUE, TRUE); /* Create the {n} triangular walls */ int i, j; for (i = 0; i < n; i++) { t[i] = MakeTriangle(); } /* Connections between the base and the triangular walls */ for (i = 0; i < n; i++) { SetNextF(t[i], b.e[i]); } /* Connections between the triangular walls */ for (i = 0; i < n; i++) { SetNextF(NextE(t[i]), Clock(PrevE(t[(i+1) % n ]))); } /* Set the common elements: edges and nodes */ for (j = 0; j < n; j++) { Place_t a = t[j]; Place_t b = NextE(a); Place_t c = PrevE(a); { SetRingEdgeInfo(a, PEdge(a)); SetOrgAll(a, OrgV(a)); SetRingEdgeInfo(b, PEdge(b)); SetOrgAll(b, OrgV(b)); SetRingEdgeInfo(c, PEdge(c)); SetOrgAll(c, OrgV(c)); } } return b; } Place_t MakePyram(uint order) { Place_vec_t a = MakePyramid(order); return a.e[0]; } Place_t BuildElongatedBipyr(uint n) { /* Was {MakeElongated} in {MakeBipyramid.m3}. */ /* Was also {MakeElongBip} in {MakeElongBip.m3}. */ demand (n >= 3, "order too small"); EightPlaces_t a[4*n]; /* Create the tetrahedra: */ int i; for (i = 0; i < 4*n; i++) { a[i] = MakeTetraTopo(1,1); } /* Meld the first level: */ for (i = 0; i < n; i++) { Glue(Spin(a[(i+1) % n].p[1]),a[i].p[0], 1, TRUE); } /* Meld the middle level: */ for (i = 0; i < n; i++) { Glue(Spin(a[i].p[3]), a[i+n].p[2], 1, TRUE); } for (i = n; i < 2*n; i++) { Glue(Clock(PrevE(a[i].p[0])), a[i+n].p[0], 1, TRUE); if (i == 2*n-1) { Glue( Clock(PrevE(a[n].p[1])), a[n+i].p[1], 1, TRUE); } else { Glue( Clock(PrevE(a[i+1].p[1])), a[n+i].p[1],1, TRUE); } } /* Meld the last level: */ for (i = 2*n; i < 3*n; i++) { Glue(Spin(a[i].p[2]), a[i+n].p[7], 1, TRUE); } for (i = 3*n; i < 4*n; i++) { if (i == 4*n-1) { Glue(Spin(a[3*n].p[1]), a[i].p[0], 1, TRUE); } else { Glue(Spin(a[i+1].p[1]), a[i].p[0], 1, TRUE); } } /* Emphasize the original elements: */ SetExWallsOfEdge(a[0].p[1], FALSE); SetExEdge(a[0].p[1], FALSE); SetExWallsOfEdge(a[2*n-1].p[1], FALSE); SetExEdge(a[4*n-1].p[1], FALSE); SetExNode(a[2*n-1].p[1], FALSE); for (i = 0; i < n; i++) { SetExWallsOfEdge(NextE(a[i].p[1]), FALSE); } for (i = n; i < 2*n; i++) { SetExEdge(PrevE(a[i].p[1]), FALSE); } for (i = 3*n; i < 4*n; i++) { SetExWallsOfEdge(PrevE(a[i].p[1]), FALSE); SetExEdge(PrevE(a[i].p[1]), FALSE); } return a[0].p[1]; } Place_t BuildSimpleBipyr(uint n, bool_t open) { /* Create {n} tetrahedra {a[0..n-1]}: */ EightPlaces_t a[n]; int i; for (i = 0; i < n; i++) { a[i] = MakeTetraTopo(1,1); } /* Glue them: */ for (i = 0; i < n - 1; i++) { Glue(Spin(a[i].p[1]), a[(i+1) % n].p[0], 1, TRUE); } if (open) { fprintf(stderr, "topology: openring(%d)\n", n); } else { fprintf(stderr, "topology: bipyramid(%d)\n", n); Glue(Spin(a[n-1].p[1]), a[0].p[0], 1, TRUE); /* Emphasize the original elements */ SetExWallsOfEdge(a[0].p[1], FALSE); SetExEdge(a[0].p[1], FALSE); } return a[0].p[1]; } void FixCoordsBipyramid(Place_t p, uint order, bool_t pyramid, ElemTableRec_t *top, Coords_t *c) { int n = order; /* First, compute the coordinates on a circle of radius one: */ double dt = 2*M_PI/n; auto void SetCoords(Place_t e, r4_t cv); /* Sets the coordinates of the node {OrgV(e)} to {cv}. */ void SetCoords(Place_t e, r4_t cv) { c->e[OrgV(e)->num] = cv; } Place_t q = p; int i; for (i = 0; i < n; i++) { double theta = i*dt; double x = cos(theta), y = sin(theta); SetCoords(PrevE(q), (r4_t){{x, y, 0.0, 1.0}}); q = NextF(q); } /* Now set the coordinates of the axis endpoints: */ SetCoords(Clock(p), (r4_t){{0.0, 0.0, 1.0, 1.0}}); if (pyramid) { SetCoords(p, (r4_t){{0.0, 0.0, 0.0, 1.0}}); } else { SetCoords(p, (r4_t){{0.0, 0.0, -1.0, 1.0}}); } } #define Pyramid_C_author \ "Created by L. A. P. Lozada, 1999-2000.\n" \ "Modification history:\n" \ " 26-01-2007 : [???] Moved {MakePyramid}, {BuildElongatedBipyr},\n" \ " {BuildSimpleBipyr}, from {MakeElongBip.c} and\n" \ " {MakePyramid.c} to here."