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 "resolu.h" |
21 |
> |
#include "rterror.h" |
22 |
> |
#include "calcomp.h" |
23 |
|
|
24 |
+ |
#define ZNAME "Z`SYS`" /* z function name */ |
25 |
+ |
#define RNAME "R`SYS`" /* r function name */ |
26 |
+ |
|
27 |
|
#define PI 3.14159265358979323846 |
28 |
|
|
29 |
|
#define FTINY 1e-9 |
33 |
|
#define UP 04 |
34 |
|
#define DOWN 010 |
35 |
|
|
31 |
– |
double funvalue(), l_hermite(), l_bezier(), l_bspline(), argument(); |
36 |
|
|
37 |
+ |
void |
38 |
+ |
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 |
+ |
l_hermite(char *nm) |
53 |
+ |
{ |
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 |
+ |
l_bezier(char *nm) |
66 |
+ |
{ |
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 |
+ |
l_bspline(char *nm) |
79 |
+ |
{ |
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 |
+ |
int |
91 |
|
main(argc, argv) |
92 |
|
int argc; |
93 |
|
char *argv[]; |
94 |
|
{ |
38 |
– |
extern long eclock; |
95 |
|
char stmp[256]; |
96 |
|
char *modname; |
97 |
|
int smooth = 0; |
100 |
|
int i, nseg; |
101 |
|
int orient; |
102 |
|
|
103 |
< |
varset("PI", PI); |
104 |
< |
funset("hermite", 5, l_hermite); |
105 |
< |
funset("bezier", 5, l_bezier); |
106 |
< |
funset("bspline", 5, l_bspline); |
103 |
> |
varset("PI", ':', PI); |
104 |
> |
funset("hermite", 5, ':', l_hermite); |
105 |
> |
funset("bezier", 5, ':', l_bezier); |
106 |
> |
funset("bspline", 5, ':', l_bspline); |
107 |
|
|
108 |
|
if (argc < 6) |
109 |
|
goto userror; |
127 |
|
goto userror; |
128 |
|
modname = smooth ? "Phong" : argv[1]; |
129 |
|
|
130 |
< |
printhead(argc, argv); |
130 |
> |
fputs("# ", stdout); |
131 |
> |
printargs(argc, argv, stdout); |
132 |
|
eclock = 0; |
133 |
|
|
134 |
|
lastnz = lastnr = 0.0; |
164 |
|
printf("0\n4\n"); |
165 |
|
if (orient&(UP|DOWN)) { |
166 |
|
t = (nextnz - lastnz)/(z - lastz); |
167 |
< |
printf("\t%15.9g\t%15.9g\n", |
167 |
> |
printf("\t%18.12g\t%18.12g\n", |
168 |
|
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 |
< |
printf("\t%15.9g\t%15.9g\n", |
173 |
> |
printf("\t%18.12g\t%18.12g\n", |
174 |
|
t, lastnr - t*lastr); |
175 |
|
} else |
176 |
|
printf("\t0\t%d\n", orient&UP ? 1 : -1); |
180 |
|
orient&DOWN ? "tube" : "cylinder", |
181 |
|
argv[2], i); |
182 |
|
printf("0\n0\n7\n"); |
183 |
< |
printf("\t0\t0\t%15.9g\n", lastz); |
184 |
< |
printf("\t0\t0\t%15.9g\n", z); |
185 |
< |
printf("\t%15.9g\n", r); |
183 |
> |
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 |
|
} else if (!(orient&(UP|DOWN))) { |
187 |
|
printf("\n%s ring %s.%d\n", modname, argv[2], i); |
188 |
|
printf("0\n0\n8\n"); |
189 |
< |
printf("\t0\t0\t%15.9g\n", z); |
190 |
< |
printf("\t0\t0\t%15.9g\n", orient&IN ? 1.0 : -1.0); |
191 |
< |
printf("\t%15.9g\t%15.9g\n", lastr, r); |
189 |
> |
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 |
|
} 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 |
< |
printf("\t0\t0\t%15.9g\n", lastz); |
198 |
< |
printf("\t0\t0\t%15.9g\n", z); |
199 |
< |
printf("\t%15.9g\t%15.9g\n", lastr, r); |
197 |
> |
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 |
|
} |
201 |
|
endfor: |
202 |
|
lastz = z; lastr = r; |
204 |
|
lastnz = nz; lastnr = nr; |
205 |
|
nz = nextnz; nr = nextnr; |
206 |
|
} |
207 |
< |
quit(0); |
207 |
> |
return 0; |
208 |
|
|
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 |
< |
quit(1); |
213 |
> |
return 1; |
214 |
|
} |
215 |
|
|
216 |
|
|
160 |
– |
computen(nzp, nrp, z0, r0, z1, r1) /* compute normal */ |
161 |
– |
double *nzp, *nrp, z0, r0, z1, r1; |
162 |
– |
{ |
163 |
– |
extern double sqrt(); |
164 |
– |
double dr, dz, len; |
165 |
– |
|
166 |
– |
dz = r0 - r1; /* right angle vector */ |
167 |
– |
dr = z1 - z0; |
168 |
– |
len = sqrt(dr*dr + dz*dz); |
169 |
– |
*nzp = dz/len; |
170 |
– |
*nrp = dr/len; |
171 |
– |
} |
172 |
– |
|
173 |
– |
|
174 |
– |
eputs(msg) |
175 |
– |
char *msg; |
176 |
– |
{ |
177 |
– |
fputs(msg, stderr); |
178 |
– |
} |
179 |
– |
|
180 |
– |
|
181 |
– |
wputs(msg) |
182 |
– |
char *msg; |
183 |
– |
{ |
184 |
– |
eputs(msg); |
185 |
– |
} |
186 |
– |
|
187 |
– |
|
188 |
– |
quit(code) |
189 |
– |
{ |
190 |
– |
exit(code); |
191 |
– |
} |
192 |
– |
|
193 |
– |
|
194 |
– |
printhead(ac, av) /* print command header */ |
195 |
– |
register int ac; |
196 |
– |
register char **av; |
197 |
– |
{ |
198 |
– |
putchar('#'); |
199 |
– |
while (ac--) { |
200 |
– |
putchar(' '); |
201 |
– |
fputs(*av++, stdout); |
202 |
– |
} |
203 |
– |
putchar('\n'); |
204 |
– |
} |
205 |
– |
|
206 |
– |
|
207 |
– |
double |
208 |
– |
l_hermite() |
209 |
– |
{ |
210 |
– |
double t; |
211 |
– |
|
212 |
– |
t = argument(5); |
213 |
– |
return( argument(1)*((2.0*t-3.0)*t*t+1.0) + |
214 |
– |
argument(2)*(-2.0*t+3.0)*t*t + |
215 |
– |
argument(3)*((t-2.0)*t+1.0)*t + |
216 |
– |
argument(4)*(t-1.0)*t*t ); |
217 |
– |
} |
218 |
– |
|
219 |
– |
|
220 |
– |
double |
221 |
– |
l_bezier() |
222 |
– |
{ |
223 |
– |
double t; |
224 |
– |
|
225 |
– |
t = argument(5); |
226 |
– |
return( argument(1) * (1.+t*(-3.+t*(3.-t))) + |
227 |
– |
argument(2) * 3.*t*(1.+t*(-2.+t)) + |
228 |
– |
argument(3) * 3.*t*t*(1.-t) + |
229 |
– |
argument(4) * t*t*t ); |
230 |
– |
} |
231 |
– |
|
232 |
– |
|
233 |
– |
double |
234 |
– |
l_bspline() |
235 |
– |
{ |
236 |
– |
double t; |
237 |
– |
|
238 |
– |
t = argument(5); |
239 |
– |
return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) + |
240 |
– |
argument(2) * (2./3.+t*t*(-1.+1./2.*t)) + |
241 |
– |
argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) + |
242 |
– |
argument(4) * (1./6.*t*t*t) ); |
243 |
– |
} |