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