1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.9 |
static const char RCSid[] = "$Id: genrev.c,v 2.8 2004/08/21 11:54:06 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.8 |
#include "resolu.h" |
21 |
|
|
#include "rterror.h" |
22 |
greg |
2.6 |
#include "calcomp.h" |
23 |
greg |
1.1 |
|
24 |
greg |
1.10 |
#define ZNAME "Z`SYS`" /* z function name */ |
25 |
|
|
#define RNAME "R`SYS`" /* r function name */ |
26 |
greg |
1.1 |
|
27 |
|
|
#define PI 3.14159265358979323846 |
28 |
|
|
|
29 |
|
|
#define FTINY 1e-9 |
30 |
|
|
/* orientation */ |
31 |
|
|
#define OUT 01 |
32 |
|
|
#define IN 02 |
33 |
|
|
#define UP 04 |
34 |
|
|
#define DOWN 010 |
35 |
|
|
|
36 |
|
|
|
37 |
schorsch |
2.7 |
void |
38 |
schorsch |
2.5 |
computen(nzp, nrp, z0, r0, z1, r1) /* compute normal */ |
39 |
|
|
double *nzp, *nrp, z0, r0, z1, r1; |
40 |
|
|
{ |
41 |
|
|
double dr, dz, len; |
42 |
|
|
|
43 |
|
|
dz = r0 - r1; /* right angle vector */ |
44 |
|
|
dr = z1 - z0; |
45 |
|
|
len = sqrt(dr*dr + dz*dz); |
46 |
|
|
*nzp = dz/len; |
47 |
|
|
*nrp = dr/len; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
|
51 |
|
|
double |
52 |
greg |
2.6 |
l_hermite(char *nm) |
53 |
schorsch |
2.5 |
{ |
54 |
|
|
double t; |
55 |
|
|
|
56 |
|
|
t = argument(5); |
57 |
|
|
return( argument(1)*((2.0*t-3.0)*t*t+1.0) + |
58 |
|
|
argument(2)*(-2.0*t+3.0)*t*t + |
59 |
|
|
argument(3)*((t-2.0)*t+1.0)*t + |
60 |
|
|
argument(4)*(t-1.0)*t*t ); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
|
64 |
|
|
double |
65 |
greg |
2.6 |
l_bezier(char *nm) |
66 |
schorsch |
2.5 |
{ |
67 |
|
|
double t; |
68 |
|
|
|
69 |
|
|
t = argument(5); |
70 |
|
|
return( argument(1) * (1.+t*(-3.+t*(3.-t))) + |
71 |
|
|
argument(2) * 3.*t*(1.+t*(-2.+t)) + |
72 |
|
|
argument(3) * 3.*t*t*(1.-t) + |
73 |
|
|
argument(4) * t*t*t ); |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
|
77 |
|
|
double |
78 |
greg |
2.6 |
l_bspline(char *nm) |
79 |
schorsch |
2.5 |
{ |
80 |
|
|
double t; |
81 |
|
|
|
82 |
|
|
t = argument(5); |
83 |
|
|
return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) + |
84 |
|
|
argument(2) * (2./3.+t*t*(-1.+1./2.*t)) + |
85 |
|
|
argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) + |
86 |
|
|
argument(4) * (1./6.*t*t*t) ); |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
|
90 |
schorsch |
2.7 |
int |
91 |
greg |
1.1 |
main(argc, argv) |
92 |
|
|
int argc; |
93 |
|
|
char *argv[]; |
94 |
|
|
{ |
95 |
|
|
char stmp[256]; |
96 |
|
|
char *modname; |
97 |
|
|
int smooth = 0; |
98 |
|
|
double t, lastz, z, nextz, lastr, r, nextr; |
99 |
|
|
double lastnz, lastnr, nz, nr, nextnz, nextnr; |
100 |
|
|
int i, nseg; |
101 |
|
|
int orient; |
102 |
|
|
|
103 |
greg |
1.8 |
varset("PI", ':', PI); |
104 |
greg |
1.9 |
funset("hermite", 5, ':', l_hermite); |
105 |
|
|
funset("bezier", 5, ':', l_bezier); |
106 |
|
|
funset("bspline", 5, ':', l_bspline); |
107 |
greg |
1.1 |
|
108 |
|
|
if (argc < 6) |
109 |
|
|
goto userror; |
110 |
|
|
|
111 |
|
|
for (i = 6; i < argc; i++) |
112 |
|
|
if (!strcmp(argv[i], "-e")) |
113 |
greg |
1.7 |
scompile(argv[++i], NULL, 0); |
114 |
greg |
1.1 |
else if (!strcmp(argv[i], "-f")) |
115 |
|
|
fcompile(argv[++i]); |
116 |
|
|
else if (!strcmp(argv[i], "-s")) |
117 |
|
|
smooth = 1; |
118 |
|
|
else |
119 |
|
|
goto userror; |
120 |
|
|
|
121 |
|
|
sprintf(stmp, "%s(t)=%s;", ZNAME, argv[3]); |
122 |
greg |
1.7 |
scompile(stmp, NULL, 0); |
123 |
greg |
1.1 |
sprintf(stmp, "%s(t)=%s;", RNAME, argv[4]); |
124 |
greg |
1.7 |
scompile(stmp, NULL, 0); |
125 |
greg |
1.1 |
nseg = atoi(argv[5]); |
126 |
|
|
if (nseg <= 0) |
127 |
|
|
goto userror; |
128 |
greg |
1.3 |
modname = smooth ? "Phong" : argv[1]; |
129 |
greg |
1.1 |
|
130 |
greg |
2.8 |
fputs("# ", stdout); |
131 |
|
|
printargs(argc, argv, stdout); |
132 |
greg |
1.6 |
eclock = 0; |
133 |
greg |
1.1 |
|
134 |
|
|
lastnz = lastnr = 0.0; |
135 |
|
|
t = 0.0; |
136 |
|
|
lastz = funvalue(ZNAME, 1, &t); |
137 |
|
|
lastr = funvalue(RNAME, 1, &t); |
138 |
|
|
t = 1.0/nseg; |
139 |
|
|
z = funvalue(ZNAME, 1, &t); |
140 |
|
|
r = funvalue(RNAME, 1, &t); |
141 |
|
|
computen(&nz, &nr, lastz, lastr, z, r); |
142 |
|
|
for (i = 1; i <= nseg; i++) { |
143 |
|
|
if (i < nseg) { |
144 |
|
|
t = (double)(i+1)/nseg; |
145 |
|
|
nextz = funvalue(ZNAME, 1, &t); |
146 |
|
|
nextr = funvalue(RNAME, 1, &t); |
147 |
|
|
computen(&nextnz, &nextnr, z, r, nextz, nextr); |
148 |
|
|
} else |
149 |
|
|
nextnz = nextnr = 0.0; |
150 |
|
|
orient = 0; |
151 |
|
|
if (z < lastz-FTINY) |
152 |
|
|
orient |= DOWN; |
153 |
|
|
else if (z > lastz+FTINY) |
154 |
|
|
orient |= UP; |
155 |
|
|
if (r < lastr-FTINY) |
156 |
|
|
orient |= IN; |
157 |
|
|
else if (r > lastr+FTINY) |
158 |
|
|
orient |= OUT; |
159 |
|
|
if (!orient) |
160 |
|
|
goto endfor; |
161 |
|
|
if (smooth) { |
162 |
greg |
1.3 |
printf("\n%s texfunc Phong\n", argv[1]); |
163 |
greg |
1.1 |
printf("4 rev_dx rev_dy rev_dz rev.cal\n"); |
164 |
|
|
printf("0\n4\n"); |
165 |
|
|
if (orient&(UP|DOWN)) { |
166 |
|
|
t = (nextnz - lastnz)/(z - lastz); |
167 |
greg |
2.9 |
printf("\t%18.12g\t%18.12g\n", |
168 |
greg |
1.1 |
t, lastnz - t*lastz); |
169 |
|
|
} else |
170 |
|
|
printf("\t0\t%d\n", orient&IN ? 1 : -1); |
171 |
|
|
if (orient&(OUT|IN)) { |
172 |
|
|
t = (nextnr - lastnr)/(r - lastr); |
173 |
greg |
2.9 |
printf("\t%18.12g\t%18.12g\n", |
174 |
greg |
1.1 |
t, lastnr - t*lastr); |
175 |
|
|
} else |
176 |
|
|
printf("\t0\t%d\n", orient&UP ? 1 : -1); |
177 |
|
|
} |
178 |
|
|
if (!(orient&(IN|OUT))) { |
179 |
|
|
printf("\n%s %s %s.%d\n", modname, |
180 |
|
|
orient&DOWN ? "tube" : "cylinder", |
181 |
|
|
argv[2], i); |
182 |
|
|
printf("0\n0\n7\n"); |
183 |
greg |
2.9 |
printf("\t0\t0\t%18.12g\n", lastz); |
184 |
|
|
printf("\t0\t0\t%18.12g\n", z); |
185 |
|
|
printf("\t%18.12g\n", r); |
186 |
greg |
1.1 |
} else if (!(orient&(UP|DOWN))) { |
187 |
|
|
printf("\n%s ring %s.%d\n", modname, argv[2], i); |
188 |
|
|
printf("0\n0\n8\n"); |
189 |
greg |
2.9 |
printf("\t0\t0\t%18.12g\n", z); |
190 |
|
|
printf("\t0\t0\t%18.12g\n", orient&IN ? 1.0 : -1.0); |
191 |
|
|
printf("\t%18.12g\t%18.12g\n", lastr, r); |
192 |
greg |
1.1 |
} else { |
193 |
|
|
printf("\n%s %s %s.%d\n", modname, |
194 |
|
|
orient&DOWN ? "cup" : "cone", |
195 |
|
|
argv[2], i); |
196 |
|
|
printf("0\n0\n8\n"); |
197 |
greg |
2.9 |
printf("\t0\t0\t%18.12g\n", lastz); |
198 |
|
|
printf("\t0\t0\t%18.12g\n", z); |
199 |
|
|
printf("\t%18.12g\t%18.12g\n", lastr, r); |
200 |
greg |
1.1 |
} |
201 |
|
|
endfor: |
202 |
|
|
lastz = z; lastr = r; |
203 |
|
|
z = nextz; r = nextr; |
204 |
|
|
lastnz = nz; lastnr = nr; |
205 |
|
|
nz = nextnz; nr = nextnr; |
206 |
|
|
} |
207 |
schorsch |
2.7 |
return 0; |
208 |
greg |
1.1 |
|
209 |
|
|
userror: |
210 |
|
|
fprintf(stderr, |
211 |
|
|
"Usage: %s material name z(t) r(t) nseg [-e expr] [-f file] [-s]\n", |
212 |
|
|
argv[0]); |
213 |
schorsch |
2.7 |
return 1; |
214 |
greg |
1.1 |
} |
215 |
|
|
|
216 |
|
|
|