|
|
1.1 root 1: #include <stdio.h>
2: #define READFN
3: #include <poly.h>
4:
5: extern debug;
6: Polyhedron net;
7: char names[MAXNETS][128];
8: int ns;
9: int prh = 0;
10: int prf = 0;
11:
12: main(argc, argv)
13: char **argv;
14: {
15: char *input = 0;
16: int i;
17: int plt = 1;
18:
19: for(argc--, argv++; argc-- && (**argv == '-'); argv++)
20: switch(argv[0][1])
21: {
22: case 'p':
23: plt = 0;
24: break;
25: case 'h':
26: prh++;
27: break;
28: case 'f':
29: prf++;
30: break;
31: case 'i':
32: input = &argv[0][2];
33: break;
34: }
35:
36: if((ns = poly_finit(input)) == 0)
37: exit(1);
38: for(i = 0; i < ns; i++)
39: {
40: poly_read(&net, i);
41: strcpy(&names[i][0], net.name);
42: }
43:
44: while(*argv)
45: {
46: i = lkpoly(*argv++);
47: if(i < 0) continue;
48: poly_read(&net, i);
49: if(plt)
50: plot(&net, i);
51: else
52: pic(&net, i);
53: }
54:
55: exit(0);
56: }
57:
58: lkpoly(s)
59: char *s;
60: {
61: register i;
62: register char *ss;
63: int n = strlen(s);
64:
65: for(i = 0; i < ns; i++)
66: if(strncmp(&names[i][0], s, n) == 0) return(i);
67: for(ss = s; *ss; ss++)
68: if((*ss < '0') || (*ss > '9')) break;
69: if(*ss == 0)
70: {
71: n = atoi(s);
72: if((n >= 0) || (n < ns))
73: return(n);
74: fprintf(stderr, "number %d out of range\n", n);
75: return(-1);
76: }
77: fprintf(stderr, "no solid '%s'\n", s);
78: return(-1);
79: }
80:
81: plot(s, num)
82: register Polyhedron *s;
83: {
84: register Point *p, *lp;
85: register i, n;
86: float xmin, xmax, ymin, ymax, c, r, x, y;
87:
88: ymin = xmin = 999999;
89: xmax = ymax = -xmin;
90: for(i = 0; i < s->nfaces; i++)
91: {
92: p = s->pts + s->faces[i].f;
93: lp = &p[s->faces[i].n];
94: while(p < lp)
95: {
96: if(p->x > xmax) xmax = p->x;
97: if(p->x < xmin) xmin = p->x;
98: if(p->y > ymax) ymax = p->y;
99: if(p->y < ymin) ymin = p->y;
100: p++;
101: }
102: }
103: r = ymax-ymin;
104: if(r < (xmax-xmin)) r = xmax-xmin;
105: r /= 2;
106: c = (xmax+xmin)/2; xmin = c-r; xmax = c+r;
107: c = (ymax+ymin)/2; ymin = c-r; ymax = c+r;
108: printf("open\n");
109: printf("range %g %g %g %g\n", xmin, ymin, xmax, ymax);
110: printf("move %g %g\ntext %d: %s\n", xmin, ymax, num, s->name);
111: for(i = 0; i < s->nfaces; i++)
112: {
113: if(s->faces[i].n < 3) continue;
114: p = s->pts + s->faces[i].f;
115: lp = &p[s->faces[i].n];
116: n = 0;
117: x = y = 0;
118: printf("poly { { %g %g", lp[-1].x, lp[-1].y);
119: while(p < lp)
120: {
121: printf(" %g %g", p->x, p->y);
122: n++, x += p->x, y += p->y;
123: p++;
124: }
125: printf(" } }\n");
126: if(prf)
127: printf("move %g %g\ntext \\C%d\n", x/n, y/n, i);
128: }
129: printf("close\n");
130: }
131:
132: pic(s, num)
133: register Polyhedron *s;
134: {
135: register Point *p, *lp;
136: register i, n;
137: float xmin, xmax, ymin, ymax, x, y;
138:
139: ymin = xmin = 999999;
140: xmax = ymax = -xmin;
141: for(i = 0; i < s->nfaces; i++)
142: {
143: p = s->pts + s->faces[i].f;
144: lp = &p[s->faces[i].n];
145: while(p < lp)
146: {
147: if(p->x > xmax) xmax = p->x;
148: if(p->x < xmin) xmin = p->x;
149: if(p->y > ymax) ymax = p->y;
150: if(p->y < ymin) ymin = p->y;
151: p++;
152: }
153: }
154: printf(".PS\nscale=%d\n", 3);
155: printf("\"%d: %s\" at %g,%g center\n", num, s->name, (xmin+xmax)/2, ymax+.2);
156: for(i = 0; i < s->nfaces; i++)
157: {
158: if(s->faces[i].n < 3) continue;
159: p = s->pts + s->faces[i].f;
160: lp = &p[s->faces[i].n];
161: n = 0;
162: x = y = 0;
163: printf("line from %g,%g", lp[-1].x, lp[-1].y);
164: while(p < lp)
165: {
166: printf(" to %g,%g", p->x, p->y);
167: n++, x += p->x, y += p->y;
168: p++;
169: }
170: printf("\n");
171: x/=n, y/=n;
172: if(prf)
173: printf("\"%d\" at %g,%g center\n", i, x, y);
174: }
175: if(prh) for(i = 0; i < s->nhinges; i++)
176: {
177: int fc = s->hinges[i].fa;
178:
179: p = s->pts + s->faces[fc].f + s->hinges[i].ea;
180: lp = (s->hinges[i].ea == s->faces[fc].n-1)?
181: s->pts + s->faces[fc].f : p+1;
182: x = (p->x+lp->x)/2;
183: y = (p->y+lp->y)/2;
184: printf("\"\\f3\\s-3%d\\fP\\s+3\" at %g,%g center\n", i, x, y);
185: }
186: printf(".PE\n");
187: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.