1 |
– |
/* |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
+ |
/* |
5 |
|
* genworm.c - program to generate worms (strings with varying thickness). |
6 |
|
* |
7 |
|
* The program takes as input the functions of t for x, y, |
11 |
|
* 9/24/87 |
12 |
|
*/ |
13 |
|
|
14 |
+ |
#include <stdlib.h> |
15 |
|
#include <stdio.h> |
16 |
+ |
#include <math.h> |
17 |
+ |
#include <string.h> |
18 |
|
|
19 |
+ |
#include "calcomp.h" |
20 |
+ |
#include "resolu.h" |
21 |
+ |
#include "rterror.h" |
22 |
|
#include "fvect.h" |
23 |
|
|
24 |
< |
#define XNAME "X_" /* x function name */ |
25 |
< |
#define YNAME "Y_" /* y function name */ |
26 |
< |
#define ZNAME "Z_" /* z function name */ |
27 |
< |
#define RNAME "R_" /* r function name */ |
24 |
> |
#define XNAME "X`SYS`" /* x function name */ |
25 |
> |
#define YNAME "Y`SYS`" /* y function name */ |
26 |
> |
#define ZNAME "Z`SYS`" /* z function name */ |
27 |
> |
#define RNAME "R`SYS`" /* r function name */ |
28 |
|
|
29 |
|
#define PI 3.14159265358979323846 |
30 |
|
|
26 |
– |
#define FTINY 1e-7 |
27 |
– |
|
31 |
|
#define max(a,b) ((a) > (b) ? (a) : (b)) |
32 |
|
|
33 |
|
|
34 |
< |
double funvalue(), l_hermite(), argument(); |
34 |
> |
/* XXX redundant, move to library */ |
35 |
> |
double l_hermite(char *), l_bezier(char *), l_bspline(char *); |
36 |
|
|
37 |
|
|
38 |
+ |
int |
39 |
|
main(argc, argv) |
40 |
|
int argc; |
41 |
|
char *argv[]; |
42 |
|
{ |
43 |
|
char stmp[256]; |
44 |
< |
double t, f, lastr, r; |
44 |
> |
double t, f, lastr = 0, r; |
45 |
|
FVECT lastp, p; |
46 |
|
int i, nseg; |
47 |
|
|
48 |
< |
varset("PI", PI, NULL); |
49 |
< |
funset("hermite", 5, l_hermite); |
48 |
> |
varset("PI", ':', PI); |
49 |
> |
funset("hermite", 5, ':', l_hermite); |
50 |
> |
funset("bezier", 5, ':', l_bezier); |
51 |
> |
funset("bspline", 5, ':', l_bspline); |
52 |
|
|
53 |
|
if (argc < 8) |
54 |
|
goto userror; |
55 |
|
|
56 |
|
for (i = 8; i < argc; i++) |
57 |
|
if (!strcmp(argv[i], "-e")) |
58 |
< |
scompile(NULL, argv[++i]); |
58 |
> |
scompile(argv[++i], NULL, 0); |
59 |
|
else if (!strcmp(argv[i], "-f")) |
60 |
|
fcompile(argv[++i]); |
61 |
|
else |
62 |
|
goto userror; |
63 |
|
|
64 |
|
sprintf(stmp, "%s(t)=%s;", XNAME, argv[3]); |
65 |
< |
scompile(NULL, stmp); |
65 |
> |
scompile(stmp, NULL, 0); |
66 |
|
sprintf(stmp, "%s(t)=%s;", YNAME, argv[4]); |
67 |
< |
scompile(NULL, stmp); |
67 |
> |
scompile(stmp, NULL, 0); |
68 |
|
sprintf(stmp, "%s(t)=%s;", ZNAME, argv[5]); |
69 |
< |
scompile(NULL, stmp); |
69 |
> |
scompile(stmp, NULL, 0); |
70 |
|
sprintf(stmp, "%s(t)=%s;", RNAME, argv[6]); |
71 |
< |
scompile(NULL, stmp); |
71 |
> |
scompile(stmp, NULL, 0); |
72 |
|
nseg = atoi(argv[7]); |
73 |
|
if (nseg <= 0) |
74 |
|
goto userror; |
75 |
|
|
76 |
< |
printhead(argc, argv); |
76 |
> |
fputs("# ", stdout); |
77 |
> |
printargs(argc, argv, stdout); |
78 |
> |
eclock = 0; |
79 |
|
|
80 |
|
for (i = 0; i <= nseg; i++) { |
81 |
|
t = (double)i/nseg; |
83 |
|
p[1] = funvalue(YNAME, 1, &t); |
84 |
|
p[2] = funvalue(ZNAME, 1, &t); |
85 |
|
r = funvalue(RNAME, 1, &t); |
86 |
< |
if (i) |
86 |
> |
if (i) { |
87 |
|
if (lastr <= r+FTINY && lastr >= r-FTINY) { |
88 |
|
printf("\n%s cylinder %s.c%d\n", |
89 |
|
argv[1], argv[2], i); |
110 |
|
f = f <= 0.0 ? 0.0 : sqrt(f); |
111 |
|
printf("%18.12g %18.12g\n", f*lastr, f*r); |
112 |
|
} |
113 |
+ |
} |
114 |
|
printf("\n%s sphere %s.s%d\n", argv[1], argv[2], i); |
115 |
|
printf("0\n0\n4 %18.12g %18.12g %18.12g %18.12g\n", |
116 |
|
p[0], p[1], p[2], r); |
117 |
|
VCOPY(lastp, p); |
118 |
|
lastr = r; |
119 |
|
} |
120 |
< |
quit(0); |
120 |
> |
return 0; |
121 |
|
|
122 |
|
userror: |
123 |
|
fprintf(stderr, |
124 |
|
"Usage: %s material name x(t) y(t) z(t) r(t) nseg [-e expr] [-f file]\n", |
125 |
|
argv[0]); |
126 |
< |
quit(1); |
126 |
> |
return 1; |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
< |
eputs(msg) |
131 |
< |
char *msg; |
130 |
> |
double |
131 |
> |
l_hermite(char *nm) |
132 |
|
{ |
133 |
< |
fputs(msg, stderr); |
133 |
> |
double t; |
134 |
> |
|
135 |
> |
t = argument(5); |
136 |
> |
return( argument(1)*((2.0*t-3.0)*t*t+1.0) + |
137 |
> |
argument(2)*(-2.0*t+3.0)*t*t + |
138 |
> |
argument(3)*((t-2.0)*t+1.0)*t + |
139 |
> |
argument(4)*(t-1.0)*t*t ); |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
< |
wputs(msg) |
144 |
< |
char *msg; |
143 |
> |
double |
144 |
> |
l_bezier(char *nm) |
145 |
|
{ |
146 |
< |
eputs(msg); |
131 |
< |
} |
146 |
> |
double t; |
147 |
|
|
148 |
< |
|
149 |
< |
quit(code) |
150 |
< |
{ |
151 |
< |
exit(code); |
148 |
> |
t = argument(5); |
149 |
> |
return( argument(1) * (1.+t*(-3.+t*(3.-t))) + |
150 |
> |
argument(2) * 3.*t*(1.+t*(-2.+t)) + |
151 |
> |
argument(3) * 3.*t*t*(1.-t) + |
152 |
> |
argument(4) * t*t*t ); |
153 |
|
} |
154 |
|
|
155 |
|
|
140 |
– |
printhead(ac, av) /* print command header */ |
141 |
– |
register int ac; |
142 |
– |
register char **av; |
143 |
– |
{ |
144 |
– |
putchar('#'); |
145 |
– |
while (ac--) { |
146 |
– |
putchar(' '); |
147 |
– |
fputs(*av++, stdout); |
148 |
– |
} |
149 |
– |
putchar('\n'); |
150 |
– |
} |
151 |
– |
|
152 |
– |
|
156 |
|
double |
157 |
< |
l_hermite() |
157 |
> |
l_bspline(char *nm) |
158 |
|
{ |
159 |
|
double t; |
160 |
< |
|
160 |
> |
|
161 |
|
t = argument(5); |
162 |
< |
return( argument(1)*((2.0*t-3.0)*t*t+1.0) + |
163 |
< |
argument(2)*(-2.0*t+3.0)*t*t + |
164 |
< |
argument(3)*((t-2.0)*t+1.0)*t + |
165 |
< |
argument(4)*(t-1.0)*t*t ); |
162 |
> |
return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) + |
163 |
> |
argument(2) * (2./3.+t*t*(-1.+1./2.*t)) + |
164 |
> |
argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) + |
165 |
> |
argument(4) * (1./6.*t*t*t) ); |
166 |
|
} |