1 |
– |
/* Copyright (c) 1989 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
|
static char SCCSid[] = "$SunId$ LBL"; |
3 |
|
#endif |
4 |
|
|
5 |
+ |
/* Copyright (c) 1989 Regents of the University of California */ |
6 |
+ |
|
7 |
|
/* |
8 |
|
* genworm.c - program to generate worms (strings with varying thickness). |
9 |
|
* |
18 |
|
|
19 |
|
#include "fvect.h" |
20 |
|
|
21 |
< |
#define XNAME "X_" /* x function name */ |
22 |
< |
#define YNAME "Y_" /* y function name */ |
23 |
< |
#define ZNAME "Z_" /* z function name */ |
24 |
< |
#define RNAME "R_" /* r function name */ |
21 |
> |
#define XNAME "X`SYS`" /* x function name */ |
22 |
> |
#define YNAME "Y`SYS`" /* y function name */ |
23 |
> |
#define ZNAME "Z`SYS`" /* z function name */ |
24 |
> |
#define RNAME "R`SYS`" /* r function name */ |
25 |
|
|
26 |
|
#define PI 3.14159265358979323846 |
27 |
|
|
30 |
|
#define max(a,b) ((a) > (b) ? (a) : (b)) |
31 |
|
|
32 |
|
|
33 |
< |
double funvalue(), l_hermite(), argument(); |
33 |
> |
double funvalue(), l_hermite(), l_bezier(), l_bspline(), argument(); |
34 |
|
|
35 |
|
|
36 |
|
main(argc, argv) |
37 |
|
int argc; |
38 |
|
char *argv[]; |
39 |
|
{ |
40 |
+ |
extern long eclock; |
41 |
|
char stmp[256]; |
42 |
|
double t, f, lastr, r; |
43 |
|
FVECT lastp, p; |
44 |
|
int i, nseg; |
45 |
|
|
46 |
< |
varset("PI", PI, NULL); |
47 |
< |
funset("hermite", 5, l_hermite); |
46 |
> |
varset("PI", ':', PI); |
47 |
> |
funset("hermite", 5, ':', l_hermite); |
48 |
> |
funset("bezier", 5, ':', l_bezier); |
49 |
> |
funset("bspline", 5, ':', l_bspline); |
50 |
|
|
51 |
|
if (argc < 8) |
52 |
|
goto userror; |
53 |
|
|
54 |
|
for (i = 8; i < argc; i++) |
55 |
|
if (!strcmp(argv[i], "-e")) |
56 |
< |
scompile(NULL, argv[++i]); |
56 |
> |
scompile(argv[++i], NULL, 0); |
57 |
|
else if (!strcmp(argv[i], "-f")) |
58 |
|
fcompile(argv[++i]); |
59 |
|
else |
60 |
|
goto userror; |
61 |
|
|
62 |
|
sprintf(stmp, "%s(t)=%s;", XNAME, argv[3]); |
63 |
< |
scompile(NULL, stmp); |
63 |
> |
scompile(stmp, NULL, 0); |
64 |
|
sprintf(stmp, "%s(t)=%s;", YNAME, argv[4]); |
65 |
< |
scompile(NULL, stmp); |
65 |
> |
scompile(stmp, NULL, 0); |
66 |
|
sprintf(stmp, "%s(t)=%s;", ZNAME, argv[5]); |
67 |
< |
scompile(NULL, stmp); |
67 |
> |
scompile(stmp, NULL, 0); |
68 |
|
sprintf(stmp, "%s(t)=%s;", RNAME, argv[6]); |
69 |
< |
scompile(NULL, stmp); |
69 |
> |
scompile(stmp, NULL, 0); |
70 |
|
nseg = atoi(argv[7]); |
71 |
|
if (nseg <= 0) |
72 |
|
goto userror; |
73 |
|
|
74 |
|
printhead(argc, argv); |
75 |
+ |
eclock = 0; |
76 |
|
|
77 |
|
for (i = 0; i <= nseg; i++) { |
78 |
|
t = (double)i/nseg; |
166 |
|
argument(2)*(-2.0*t+3.0)*t*t + |
167 |
|
argument(3)*((t-2.0)*t+1.0)*t + |
168 |
|
argument(4)*(t-1.0)*t*t ); |
169 |
+ |
} |
170 |
+ |
|
171 |
+ |
|
172 |
+ |
double |
173 |
+ |
l_bezier() |
174 |
+ |
{ |
175 |
+ |
double t; |
176 |
+ |
|
177 |
+ |
t = argument(5); |
178 |
+ |
return( argument(1) * (1.+t*(-3.+t*(3.-t))) + |
179 |
+ |
argument(2) * 3.*t*(1.+t*(-2.+t)) + |
180 |
+ |
argument(3) * 3.*t*t*(1.-t) + |
181 |
+ |
argument(4) * t*t*t ); |
182 |
+ |
} |
183 |
+ |
|
184 |
+ |
|
185 |
+ |
double |
186 |
+ |
l_bspline() |
187 |
+ |
{ |
188 |
+ |
double t; |
189 |
+ |
|
190 |
+ |
t = argument(5); |
191 |
+ |
return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) + |
192 |
+ |
argument(2) * (2./3.+t*t*(-1.+1./2.*t)) + |
193 |
+ |
argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) + |
194 |
+ |
argument(4) * (1./6.*t*t*t) ); |
195 |
|
} |