1 |
greg |
1.1 |
/* |
2 |
|
|
|
3 |
|
|
#ifndef lint |
4 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
|
#endif |
6 |
|
|
* genrev.c - program to generate functions of rotation about z |
7 |
|
|
* |
8 |
|
|
* The program takes as input the functions of t for z and r |
9 |
|
|
* (the radius). If z is increasing, the normal points |
10 |
|
|
* outward, inward for decreasing z. Negative radii are forbidden. |
11 |
|
|
* |
12 |
|
|
* 8/6/86 |
13 |
|
|
*/ |
14 |
|
|
|
15 |
|
|
#include <stdio.h> |
16 |
|
|
|
17 |
|
|
#define ZNAME "Z_" /* z function name */ |
18 |
|
|
#define RNAME "R_" /* r function name */ |
19 |
|
|
|
20 |
|
|
#define PI 3.14159265358979323846 |
21 |
|
|
|
22 |
|
|
#define FTINY 1e-9 |
23 |
|
|
/* orientation */ |
24 |
|
|
#define OUT 01 |
25 |
|
|
#define IN 02 |
26 |
|
|
#define UP 04 |
27 |
|
|
#define DOWN 010 |
28 |
|
|
|
29 |
|
|
double funvalue(), l_hermite(), argument(); |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
main(argc, argv) |
33 |
|
|
int argc; |
34 |
|
|
char *argv[]; |
35 |
|
|
{ |
36 |
|
|
char stmp[256]; |
37 |
|
|
char *modname; |
38 |
|
|
int smooth = 0; |
39 |
|
|
double t, lastz, z, nextz, lastr, r, nextr; |
40 |
|
|
double lastnz, lastnr, nz, nr, nextnz, nextnr; |
41 |
|
|
int i, nseg; |
42 |
|
|
int orient; |
43 |
|
|
|
44 |
|
|
varset("PI", PI); |
45 |
|
|
funset("hermite", 5, l_hermite); |
46 |
|
|
|
47 |
|
|
if (argc < 6) |
48 |
|
|
goto userror; |
49 |
|
|
|
50 |
|
|
for (i = 6; i < argc; i++) |
51 |
|
|
if (!strcmp(argv[i], "-e")) |
52 |
|
|
scompile(NULL, argv[++i]); |
53 |
|
|
else if (!strcmp(argv[i], "-f")) |
54 |
|
|
fcompile(argv[++i]); |
55 |
|
|
else if (!strcmp(argv[i], "-s")) |
56 |
|
|
smooth = 1; |
57 |
|
|
else |
58 |
|
|
goto userror; |
59 |
|
|
|
60 |
|
|
sprintf(stmp, "%s(t)=%s;", ZNAME, argv[3]); |
61 |
|
|
scompile(NULL, stmp); |
62 |
|
|
sprintf(stmp, "%s(t)=%s;", RNAME, argv[4]); |
63 |
|
|
scompile(NULL, stmp); |
64 |
|
|
nseg = atoi(argv[5]); |
65 |
|
|
if (nseg <= 0) |
66 |
|
|
goto userror; |
67 |
|
|
modname = smooth ? "phong" : argv[1]; |
68 |
|
|
|
69 |
|
|
printhead(argc, argv); |
70 |
|
|
|
71 |
|
|
lastnz = lastnr = 0.0; |
72 |
|
|
t = 0.0; |
73 |
|
|
lastz = funvalue(ZNAME, 1, &t); |
74 |
|
|
lastr = funvalue(RNAME, 1, &t); |
75 |
|
|
t = 1.0/nseg; |
76 |
|
|
z = funvalue(ZNAME, 1, &t); |
77 |
|
|
r = funvalue(RNAME, 1, &t); |
78 |
|
|
computen(&nz, &nr, lastz, lastr, z, r); |
79 |
|
|
for (i = 1; i <= nseg; i++) { |
80 |
|
|
if (i < nseg) { |
81 |
|
|
t = (double)(i+1)/nseg; |
82 |
|
|
nextz = funvalue(ZNAME, 1, &t); |
83 |
|
|
nextr = funvalue(RNAME, 1, &t); |
84 |
|
|
computen(&nextnz, &nextnr, z, r, nextz, nextr); |
85 |
|
|
} else |
86 |
|
|
nextnz = nextnr = 0.0; |
87 |
|
|
orient = 0; |
88 |
|
|
if (z < lastz-FTINY) |
89 |
|
|
orient |= DOWN; |
90 |
|
|
else if (z > lastz+FTINY) |
91 |
|
|
orient |= UP; |
92 |
|
|
if (r < lastr-FTINY) |
93 |
|
|
orient |= IN; |
94 |
|
|
else if (r > lastr+FTINY) |
95 |
|
|
orient |= OUT; |
96 |
|
|
if (!orient) |
97 |
|
|
goto endfor; |
98 |
|
|
if (smooth) { |
99 |
|
|
printf("\n%s texfunc phong\n", argv[1]); |
100 |
|
|
printf("4 rev_dx rev_dy rev_dz rev.cal\n"); |
101 |
|
|
printf("0\n4\n"); |
102 |
|
|
if (orient&(UP|DOWN)) { |
103 |
|
|
t = (nextnz - lastnz)/(z - lastz); |
104 |
|
|
printf("\t%15.9g\t%15.9g\n", |
105 |
|
|
t, lastnz - t*lastz); |
106 |
|
|
} else |
107 |
|
|
printf("\t0\t%d\n", orient&IN ? 1 : -1); |
108 |
|
|
if (orient&(OUT|IN)) { |
109 |
|
|
t = (nextnr - lastnr)/(r - lastr); |
110 |
|
|
printf("\t%15.9g\t%15.9g\n", |
111 |
|
|
t, lastnr - t*lastr); |
112 |
|
|
} else |
113 |
|
|
printf("\t0\t%d\n", orient&UP ? 1 : -1); |
114 |
|
|
} |
115 |
|
|
if (!(orient&(IN|OUT))) { |
116 |
|
|
printf("\n%s %s %s.%d\n", modname, |
117 |
|
|
orient&DOWN ? "tube" : "cylinder", |
118 |
|
|
argv[2], i); |
119 |
|
|
printf("0\n0\n7\n"); |
120 |
|
|
printf("\t0\t0\t%15.9g\n", lastz); |
121 |
|
|
printf("\t0\t0\t%15.9g\n", z); |
122 |
|
|
printf("\t%15.9g\n", r); |
123 |
|
|
} else if (!(orient&(UP|DOWN))) { |
124 |
|
|
printf("\n%s ring %s.%d\n", modname, argv[2], i); |
125 |
|
|
printf("0\n0\n8\n"); |
126 |
|
|
printf("\t0\t0\t%15.9g\n", z); |
127 |
|
|
printf("\t0\t0\t%15.9g\n", orient&IN ? 1.0 : -1.0); |
128 |
|
|
printf("\t%15.9g\t%15.9g\n", lastr, r); |
129 |
|
|
} else { |
130 |
|
|
printf("\n%s %s %s.%d\n", modname, |
131 |
|
|
orient&DOWN ? "cup" : "cone", |
132 |
|
|
argv[2], i); |
133 |
|
|
printf("0\n0\n8\n"); |
134 |
|
|
printf("\t0\t0\t%15.9g\n", lastz); |
135 |
|
|
printf("\t0\t0\t%15.9g\n", z); |
136 |
|
|
printf("\t%15.9g\t%15.9g\n", lastr, r); |
137 |
|
|
} |
138 |
|
|
endfor: |
139 |
|
|
lastz = z; lastr = r; |
140 |
|
|
z = nextz; r = nextr; |
141 |
|
|
lastnz = nz; lastnr = nr; |
142 |
|
|
nz = nextnz; nr = nextnr; |
143 |
|
|
} |
144 |
|
|
quit(0); |
145 |
|
|
|
146 |
|
|
userror: |
147 |
|
|
fprintf(stderr, |
148 |
|
|
"Usage: %s material name z(t) r(t) nseg [-e expr] [-f file] [-s]\n", |
149 |
|
|
argv[0]); |
150 |
|
|
quit(1); |
151 |
|
|
} |
152 |
|
|
|
153 |
|
|
|
154 |
|
|
computen(nzp, nrp, z0, r0, z1, r1) /* compute normal */ |
155 |
|
|
double *nzp, *nrp, z0, r0, z1, r1; |
156 |
|
|
{ |
157 |
|
|
extern double sqrt(); |
158 |
|
|
double dr, dz, len; |
159 |
|
|
|
160 |
|
|
dz = r0 - r1; /* right angle vector */ |
161 |
|
|
dr = z1 - z0; |
162 |
|
|
len = sqrt(dr*dr + dz*dz); |
163 |
|
|
*nzp = dz/len; |
164 |
|
|
*nrp = dr/len; |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
|
168 |
|
|
eputs(msg) |
169 |
|
|
char *msg; |
170 |
|
|
{ |
171 |
|
|
fputs(msg, stderr); |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
|
175 |
|
|
wputs(msg) |
176 |
|
|
char *msg; |
177 |
|
|
{ |
178 |
|
|
eputs(msg); |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
|
182 |
|
|
quit(code) |
183 |
|
|
{ |
184 |
|
|
exit(code); |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
|
188 |
|
|
printhead(ac, av) /* print command header */ |
189 |
|
|
register int ac; |
190 |
|
|
register char **av; |
191 |
|
|
{ |
192 |
|
|
putchar('#'); |
193 |
|
|
while (ac--) { |
194 |
|
|
putchar(' '); |
195 |
|
|
fputs(*av++, stdout); |
196 |
|
|
} |
197 |
|
|
putchar('\n'); |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
|
201 |
|
|
double |
202 |
|
|
l_hermite() |
203 |
|
|
{ |
204 |
|
|
double t; |
205 |
|
|
|
206 |
|
|
t = argument(5); |
207 |
|
|
return( argument(1)*((2.0*t-3.0)*t*t+1.0) + |
208 |
|
|
argument(2)*(-2.0*t+3.0)*t*t + |
209 |
|
|
argument(3)*((t-2.0)*t+1.0)*t + |
210 |
|
|
argument(4)*(t-1.0)*t*t ); |
211 |
|
|
} |