1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
– |
|
5 |
– |
/* Copyright (c) 1989 Regents of the University of California */ |
6 |
– |
|
4 |
|
/* |
5 |
|
* genrev.c - program to generate functions of rotation about z |
6 |
|
* |
11 |
|
* 8/6/86 |
12 |
|
*/ |
13 |
|
|
14 |
+ |
#include <stdlib.h> |
15 |
|
#include <stdio.h> |
16 |
+ |
#include <string.h> |
17 |
+ |
#include <math.h> |
18 |
|
|
19 |
< |
#define ZNAME "Z_" /* z function name */ |
20 |
< |
#define RNAME "R_" /* r function name */ |
19 |
> |
#include "rterror.h" |
20 |
> |
#include "calcomp.h" |
21 |
|
|
22 |
+ |
#define ZNAME "Z`SYS`" /* z function name */ |
23 |
+ |
#define RNAME "R`SYS`" /* r function name */ |
24 |
+ |
|
25 |
|
#define PI 3.14159265358979323846 |
26 |
|
|
27 |
|
#define FTINY 1e-9 |
31 |
|
#define UP 04 |
32 |
|
#define DOWN 010 |
33 |
|
|
31 |
– |
double funvalue(), l_hermite(), l_bezier(), l_bspline(), argument(); |
34 |
|
|
35 |
+ |
void |
36 |
+ |
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 |
+ |
void |
74 |
+ |
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 |
+ |
l_hermite(char *nm) |
89 |
+ |
{ |
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 |
+ |
l_bezier(char *nm) |
102 |
+ |
{ |
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 |
+ |
l_bspline(char *nm) |
115 |
+ |
{ |
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 |
+ |
int |
127 |
|
main(argc, argv) |
128 |
|
int argc; |
129 |
|
char *argv[]; |
136 |
|
int i, nseg; |
137 |
|
int orient; |
138 |
|
|
139 |
< |
varset("PI", PI); |
140 |
< |
funset("hermite", 5, l_hermite); |
141 |
< |
funset("bezier", 5, l_bezier); |
142 |
< |
funset("bspline", 5, l_bspline); |
139 |
> |
varset("PI", ':', PI); |
140 |
> |
funset("hermite", 5, ':', l_hermite); |
141 |
> |
funset("bezier", 5, ':', l_bezier); |
142 |
> |
funset("bspline", 5, ':', l_bspline); |
143 |
|
|
144 |
|
if (argc < 6) |
145 |
|
goto userror; |
146 |
|
|
147 |
|
for (i = 6; i < argc; i++) |
148 |
|
if (!strcmp(argv[i], "-e")) |
149 |
< |
scompile(NULL, argv[++i]); |
149 |
> |
scompile(argv[++i], NULL, 0); |
150 |
|
else if (!strcmp(argv[i], "-f")) |
151 |
|
fcompile(argv[++i]); |
152 |
|
else if (!strcmp(argv[i], "-s")) |
155 |
|
goto userror; |
156 |
|
|
157 |
|
sprintf(stmp, "%s(t)=%s;", ZNAME, argv[3]); |
158 |
< |
scompile(NULL, stmp); |
158 |
> |
scompile(stmp, NULL, 0); |
159 |
|
sprintf(stmp, "%s(t)=%s;", RNAME, argv[4]); |
160 |
< |
scompile(NULL, stmp); |
160 |
> |
scompile(stmp, NULL, 0); |
161 |
|
nseg = atoi(argv[5]); |
162 |
|
if (nseg <= 0) |
163 |
|
goto userror; |
164 |
|
modname = smooth ? "Phong" : argv[1]; |
165 |
|
|
166 |
|
printhead(argc, argv); |
167 |
+ |
eclock = 0; |
168 |
|
|
169 |
|
lastnz = lastnr = 0.0; |
170 |
|
t = 0.0; |
239 |
|
lastnz = nz; lastnr = nr; |
240 |
|
nz = nextnz; nr = nextnr; |
241 |
|
} |
242 |
< |
quit(0); |
242 |
> |
return 0; |
243 |
|
|
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 |
< |
quit(1); |
248 |
> |
return 1; |
249 |
|
} |
250 |
|
|
251 |
|
|
158 |
– |
computen(nzp, nrp, z0, r0, z1, r1) /* compute normal */ |
159 |
– |
double *nzp, *nrp, z0, r0, z1, r1; |
160 |
– |
{ |
161 |
– |
extern double sqrt(); |
162 |
– |
double dr, dz, len; |
163 |
– |
|
164 |
– |
dz = r0 - r1; /* right angle vector */ |
165 |
– |
dr = z1 - z0; |
166 |
– |
len = sqrt(dr*dr + dz*dz); |
167 |
– |
*nzp = dz/len; |
168 |
– |
*nrp = dr/len; |
169 |
– |
} |
170 |
– |
|
171 |
– |
|
172 |
– |
eputs(msg) |
173 |
– |
char *msg; |
174 |
– |
{ |
175 |
– |
fputs(msg, stderr); |
176 |
– |
} |
177 |
– |
|
178 |
– |
|
179 |
– |
wputs(msg) |
180 |
– |
char *msg; |
181 |
– |
{ |
182 |
– |
eputs(msg); |
183 |
– |
} |
184 |
– |
|
185 |
– |
|
186 |
– |
quit(code) |
187 |
– |
{ |
188 |
– |
exit(code); |
189 |
– |
} |
190 |
– |
|
191 |
– |
|
192 |
– |
printhead(ac, av) /* print command header */ |
193 |
– |
register int ac; |
194 |
– |
register char **av; |
195 |
– |
{ |
196 |
– |
putchar('#'); |
197 |
– |
while (ac--) { |
198 |
– |
putchar(' '); |
199 |
– |
fputs(*av++, stdout); |
200 |
– |
} |
201 |
– |
putchar('\n'); |
202 |
– |
} |
203 |
– |
|
204 |
– |
|
205 |
– |
double |
206 |
– |
l_hermite() |
207 |
– |
{ |
208 |
– |
double t; |
209 |
– |
|
210 |
– |
t = argument(5); |
211 |
– |
return( argument(1)*((2.0*t-3.0)*t*t+1.0) + |
212 |
– |
argument(2)*(-2.0*t+3.0)*t*t + |
213 |
– |
argument(3)*((t-2.0)*t+1.0)*t + |
214 |
– |
argument(4)*(t-1.0)*t*t ); |
215 |
– |
} |
216 |
– |
|
217 |
– |
|
218 |
– |
double |
219 |
– |
l_bezier() |
220 |
– |
{ |
221 |
– |
double t; |
222 |
– |
|
223 |
– |
t = argument(5); |
224 |
– |
return( argument(1) * (1.+t*(-3.+t*(3.-t))) + |
225 |
– |
argument(2) * 3.*t*(1.+t*(-2.+t)) + |
226 |
– |
argument(3) * 3.*t*t*(1.-t) + |
227 |
– |
argument(4) * t*t*t ); |
228 |
– |
} |
229 |
– |
|
230 |
– |
|
231 |
– |
double |
232 |
– |
l_bspline() |
233 |
– |
{ |
234 |
– |
double t; |
235 |
– |
|
236 |
– |
t = argument(5); |
237 |
– |
return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) + |
238 |
– |
argument(2) * (2./3.+t*t*(-1.+1./2.*t)) + |
239 |
– |
argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) + |
240 |
– |
argument(4) * (1./6.*t*t*t) ); |
241 |
– |
} |