--- ray/src/gen/genworm.c 1990/03/02 17:24:05 1.3 +++ ray/src/gen/genworm.c 1993/01/05 10:06:59 2.2 @@ -1,9 +1,9 @@ -/* Copyright (c) 1989 Regents of the University of California */ - #ifndef lint static char SCCSid[] = "$SunId$ LBL"; #endif +/* Copyright (c) 1989 Regents of the University of California */ + /* * genworm.c - program to generate worms (strings with varying thickness). * @@ -15,61 +15,62 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include - +#include #include "fvect.h" -#define XNAME "X_" /* x function name */ -#define YNAME "Y_" /* y function name */ -#define ZNAME "Z_" /* z function name */ -#define RNAME "R_" /* r function name */ +#define XNAME "X`SYS`" /* x function name */ +#define YNAME "Y`SYS`" /* y function name */ +#define ZNAME "Z`SYS`" /* z function name */ +#define RNAME "R`SYS`" /* r function name */ #define PI 3.14159265358979323846 -#define FTINY 1e-7 - #define max(a,b) ((a) > (b) ? (a) : (b)) -double funvalue(), l_hermite(), l_bezier(), argument(); +double funvalue(), l_hermite(), l_bezier(), l_bspline(), argument(); main(argc, argv) int argc; char *argv[]; { + extern long eclock; char stmp[256]; double t, f, lastr, r; FVECT lastp, p; int i, nseg; - varset("PI", PI, NULL); - funset("hermite", 5, l_hermite); - funset("bezier", 5, l_bezier); + varset("PI", ':', PI); + funset("hermite", 5, ':', l_hermite); + funset("bezier", 5, ':', l_bezier); + funset("bspline", 5, ':', l_bspline); if (argc < 8) goto userror; for (i = 8; i < argc; i++) if (!strcmp(argv[i], "-e")) - scompile(NULL, argv[++i]); + scompile(argv[++i], NULL, 0); else if (!strcmp(argv[i], "-f")) fcompile(argv[++i]); else goto userror; sprintf(stmp, "%s(t)=%s;", XNAME, argv[3]); - scompile(NULL, stmp); + scompile(stmp, NULL, 0); sprintf(stmp, "%s(t)=%s;", YNAME, argv[4]); - scompile(NULL, stmp); + scompile(stmp, NULL, 0); sprintf(stmp, "%s(t)=%s;", ZNAME, argv[5]); - scompile(NULL, stmp); + scompile(stmp, NULL, 0); sprintf(stmp, "%s(t)=%s;", RNAME, argv[6]); - scompile(NULL, stmp); + scompile(stmp, NULL, 0); nseg = atoi(argv[7]); if (nseg <= 0) goto userror; printhead(argc, argv); + eclock = 0; for (i = 0; i <= nseg; i++) { t = (double)i/nseg; @@ -176,4 +177,17 @@ l_bezier() argument(2) * 3.*t*(1.+t*(-2.+t)) + argument(3) * 3.*t*t*(1.-t) + argument(4) * t*t*t ); +} + + +double +l_bspline() +{ + double t; + + t = argument(5); + return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) + + argument(2) * (2./3.+t*t*(-1.+1./2.*t)) + + argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) + + argument(4) * (1./6.*t*t*t) ); }