ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genworm.c
(Generate patch)

Comparing ray/src/gen/genworm.c (file contents):
Revision 1.1 by greg, Thu Feb 2 11:16:31 1989 UTC vs.
Revision 1.10 by greg, Mon Oct 28 16:13:30 1991 UTC

# Line 1 | Line 1
1 /*
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   *
10   *      The program takes as input the functions of t for x, y,
# Line 16 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
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  
26 #define  FTINY          1e-7
27
28   #define  max(a,b)       ((a) > (b) ? (a) : (b))
29  
30  
31 < double  funvalue(), l_hermite(), argument();
31 > double  funvalue(), l_hermite(), l_bezier(), l_bspline(), argument();
32  
33  
34   main(argc, argv)
35   int  argc;
36   char  *argv[];
37   {
38 +        extern long     eclock;
39          char  stmp[256];
40          double  t, f, lastr, r;
41          FVECT  lastp, p;
42          int  i, nseg;
43  
44 <        varset("PI", PI, NULL);
45 <        funset("hermite", 5, l_hermite);
44 >        varset("PI", ':', PI);
45 >        funset("hermite", 5, ':', l_hermite);
46 >        funset("bezier", 5, ':', l_bezier);
47 >        funset("bspline", 5, ':', l_bspline);
48  
49          if (argc < 8)
50                  goto userror;
51  
52          for (i = 8; i < argc; i++)
53                  if (!strcmp(argv[i], "-e"))
54 <                        scompile(NULL, argv[++i]);
54 >                        scompile(argv[++i], NULL, 0);
55                  else if (!strcmp(argv[i], "-f"))
56                          fcompile(argv[++i]);
57                  else
58                          goto userror;
59  
60          sprintf(stmp, "%s(t)=%s;", XNAME, argv[3]);
61 <        scompile(NULL, stmp);
61 >        scompile(stmp, NULL, 0);
62          sprintf(stmp, "%s(t)=%s;", YNAME, argv[4]);
63 <        scompile(NULL, stmp);
63 >        scompile(stmp, NULL, 0);
64          sprintf(stmp, "%s(t)=%s;", ZNAME, argv[5]);
65 <        scompile(NULL, stmp);
65 >        scompile(stmp, NULL, 0);
66          sprintf(stmp, "%s(t)=%s;", RNAME, argv[6]);
67 <        scompile(NULL, stmp);
67 >        scompile(stmp, NULL, 0);
68          nseg = atoi(argv[7]);
69          if (nseg <= 0)
70                  goto userror;
71  
72          printhead(argc, argv);
73 +        eclock = 0;
74  
75          for (i = 0; i <= nseg; i++) {
76                  t = (double)i/nseg;
# Line 160 | Line 164 | l_hermite()                    
164                  argument(2)*(-2.0*t+3.0)*t*t +
165                  argument(3)*((t-2.0)*t+1.0)*t +
166                  argument(4)*(t-1.0)*t*t );
167 + }
168 +
169 +
170 + double
171 + l_bezier()
172 + {
173 +        double  t;
174 +
175 +        t = argument(5);
176 +        return( argument(1) * (1.+t*(-3.+t*(3.-t))) +
177 +                argument(2) * 3.*t*(1.+t*(-2.+t)) +
178 +                argument(3) * 3.*t*t*(1.-t) +
179 +                argument(4) * t*t*t );
180 + }
181 +
182 +
183 + double
184 + l_bspline()
185 + {
186 +        double  t;
187 +
188 +        t = argument(5);
189 +        return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) +
190 +                argument(2) * (2./3.+t*t*(-1.+1./2.*t)) +
191 +                argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) +
192 +                argument(4) * (1./6.*t*t*t) );
193   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines