ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genworm.c
Revision: 2.3
Committed: Thu Nov 18 09:33:07 1993 UTC (30 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +1 -0 lines
Log Message:
minor compiler warning fixes

File Contents

# Content
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,
11 * z and r (the radius). Cylinders and cones will be
12 * joined by spheres. Negative radii are forbidden.
13 *
14 * 9/24/87
15 */
16
17 #include <stdio.h>
18 #include <math.h>
19 #include "fvect.h"
20
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
28 #define max(a,b) ((a) > (b) ? (a) : (b))
29
30
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);
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(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(stmp, NULL, 0);
62 sprintf(stmp, "%s(t)=%s;", YNAME, argv[4]);
63 scompile(stmp, NULL, 0);
64 sprintf(stmp, "%s(t)=%s;", ZNAME, argv[5]);
65 scompile(stmp, NULL, 0);
66 sprintf(stmp, "%s(t)=%s;", RNAME, argv[6]);
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;
77 p[0] = funvalue(XNAME, 1, &t);
78 p[1] = funvalue(YNAME, 1, &t);
79 p[2] = funvalue(ZNAME, 1, &t);
80 r = funvalue(RNAME, 1, &t);
81 if (i)
82 if (lastr <= r+FTINY && lastr >= r-FTINY) {
83 printf("\n%s cylinder %s.c%d\n",
84 argv[1], argv[2], i);
85 printf("0\n0\n7\n");
86 printf("%18.12g %18.12g %18.12g\n",
87 lastp[0], lastp[1], lastp[2]);
88 printf("%18.12g %18.12g %18.12g\n",
89 p[0], p[1], p[2]);
90 printf("%18.12g\n", r);
91 } else {
92 printf("\n%s cone %s.c%d\n",
93 argv[1], argv[2], i);
94 printf("0\n0\n8\n");
95 f = (lastr - r)/dist2(lastp,p);
96 printf("%18.12g %18.12g %18.12g\n",
97 lastp[0] + f*lastr*(p[0] - lastp[0]),
98 lastp[1] + f*lastr*(p[1] - lastp[1]),
99 lastp[2] + f*lastr*(p[2] - lastp[2]));
100 printf("%18.12g %18.12g %18.12g\n",
101 p[0] + f*r*(p[0] - lastp[0]),
102 p[1] + f*r*(p[1] - lastp[1]),
103 p[2] + f*r*(p[2] - lastp[2]));
104 f = 1.0 - (lastr-r)*f;
105 f = f <= 0.0 ? 0.0 : sqrt(f);
106 printf("%18.12g %18.12g\n", f*lastr, f*r);
107 }
108 printf("\n%s sphere %s.s%d\n", argv[1], argv[2], i);
109 printf("0\n0\n4 %18.12g %18.12g %18.12g %18.12g\n",
110 p[0], p[1], p[2], r);
111 VCOPY(lastp, p);
112 lastr = r;
113 }
114 quit(0);
115
116 userror:
117 fprintf(stderr,
118 "Usage: %s material name x(t) y(t) z(t) r(t) nseg [-e expr] [-f file]\n",
119 argv[0]);
120 quit(1);
121 }
122
123
124 eputs(msg)
125 char *msg;
126 {
127 fputs(msg, stderr);
128 }
129
130
131 wputs(msg)
132 char *msg;
133 {
134 eputs(msg);
135 }
136
137
138 quit(code)
139 int code;
140 {
141 exit(code);
142 }
143
144
145 printhead(ac, av) /* print command header */
146 register int ac;
147 register char **av;
148 {
149 putchar('#');
150 while (ac--) {
151 putchar(' ');
152 fputs(*av++, stdout);
153 }
154 putchar('\n');
155 }
156
157
158 double
159 l_hermite()
160 {
161 double t;
162
163 t = argument(5);
164 return( argument(1)*((2.0*t-3.0)*t*t+1.0) +
165 argument(2)*(-2.0*t+3.0)*t*t +
166 argument(3)*((t-2.0)*t+1.0)*t +
167 argument(4)*(t-1.0)*t*t );
168 }
169
170
171 double
172 l_bezier()
173 {
174 double t;
175
176 t = argument(5);
177 return( argument(1) * (1.+t*(-3.+t*(3.-t))) +
178 argument(2) * 3.*t*(1.+t*(-2.+t)) +
179 argument(3) * 3.*t*t*(1.-t) +
180 argument(4) * t*t*t );
181 }
182
183
184 double
185 l_bspline()
186 {
187 double t;
188
189 t = argument(5);
190 return( argument(1) * (1./6.+t*(-1./2.+t*(1./2.-1./6.*t))) +
191 argument(2) * (2./3.+t*t*(-1.+1./2.*t)) +
192 argument(3) * (1./6.+t*(1./2.+t*(1./2.-1./2.*t))) +
193 argument(4) * (1./6.*t*t*t) );
194 }