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

Comparing ray/src/gen/genprism.c (file contents):
Revision 2.6 by greg, Tue Mar 19 16:30:56 1996 UTC vs.
Revision 2.7 by greg, Tue Mar 19 20:59:22 1996 UTC

# Line 30 | Line 30 | char  *pmtype;         /* material type */
30   char  *pname;           /* name */
31  
32   double  lvect[3] = {0.0, 0.0, 1.0};
33 + int     lvdir = 1;
34   double  llen = 1.0;
35  
36   double  vert[MAXVERT][2];
# Line 40 | Line 41 | double a[MAXVERT];             /* corner trim sizes */
41  
42   int  do_ends = 1;               /* include end caps */
43   int  iscomplete = 0;            /* polygon is already completed */
44 < double  crad = 0.0;             /* radius for corners */
44 > double  crad = 0.0;             /* radius for corners (sign from lvdir) */
45  
46 < #define rounding        (crad > FTINY)
46 > extern double  compute_rounding();
47  
48  
49   main(argc, argv)
# Line 86 | Line 87 | char  **argv;
87                          lvect[0] = atof(argv[++an]);
88                          lvect[1] = atof(argv[++an]);
89                          lvect[2] = atof(argv[++an]);
90 <                        llen = sqrt(lvect[0]*lvect[0] + lvect[1]*lvect[1] +
91 <                                        lvect[2]*lvect[2]);
92 <                        if (llen <= FTINY) {
93 <                                fprintf(stderr, "%s: zero extrusion vector\n",
90 >                        if (lvect[2] < -FTINY)
91 >                                lvdir = -1;
92 >                        else if (lvect[2] > FTINY)
93 >                                lvdir = 1;
94 >                        else {
95 >                                fprintf(stderr,
96 >                                        "%s: illegal extrusion vector\n",
97                                                  argv[0]);
98                                  exit(1);
99                          }
100 +                        llen = sqrt(lvect[0]*lvect[0] + lvect[1]*lvect[1] +
101 +                                        lvect[2]*lvect[2]);
102                          break;
103                  case 'r':                               /* radius */
104                          crad = atof(argv[++an]);
# Line 107 | Line 113 | char  **argv;
113                          goto userr;
114                  }
115          }
116 <        if (rounding) {
117 <                if (crad > fabs(lvect[2])) {
116 >        if (crad > FTINY) {
117 >                if (crad > lvdir*lvect[2]) {
118                          fprintf(stderr, "%s: rounding greater than height\n",
119                                          argv[0]);
120                          exit(1);
121                  }
122 +                crad *= lvdir;          /* simplifies formulas */
123                  compute_rounding();
124 <        }
125 <        printhead(argc, argv);
119 <
120 <        if (do_ends)
121 <                if (rounding)
124 >                printhead(argc, argv);
125 >                if (do_ends)
126                          printrends();
127 <                else
127 >                printsides(1);
128 >        } else {
129 >                printhead(argc, argv);
130 >                if (do_ends)
131                          printends();
132 <
133 <        printsides(rounding);
127 <
132 >                printsides(0);
133 >        }
134          exit(0);
135   userr:
136          fprintf(stderr, "Usage: %s material name ", argv[0]);
# Line 151 | Line 157 | char  *fname;
157   }
158  
159  
160 + double
161   compute_rounding()              /* compute vectors for rounding operations */
162   {
163          register int  i;
164          register double *v0, *v1;
165 <        double  l;
165 >        double  l, asum;
166  
167          v0 = vert[nverts-1];
168          for (i = 0; i < nverts; i++) {          /* compute u[*] */
# Line 171 | Line 178 | compute_rounding()             /* compute vectors for rounding op
178                  u[i][1] /= l;
179                  v0 = v1;
180          }
181 +        asum = 0.;
182          v1 = u[0];
183          for (i = nverts; i--; ) {               /* compute a[*] */
184                  v0 = u[i];
# Line 183 | Line 191 | compute_rounding()             /* compute vectors for rounding op
191                          a[i] = 0.;
192                  else {
193                          a[i] = sqrt((1-l)/(1+l));
194 <                        if ((v1[0]*v0[1]-v1[1]*v0[0] > 0.) != (lvect[2] > 0.))
194 >                        asum += l = v1[0]*v0[1]-v1[1]*v0[0];
195 >                        if (l < 0.)
196                                  a[i] = -a[i];
197                  }
198                  v1 = v0;
199          }
200 +        return(asum*.5);
201   }
202  
203  
# Line 222 | Line 232 | printrends()                   /* print ends of prism with rounding */
232                          vert[i][1] + crad*(a[i]*u[i][1] + u[i][0]),
233                          0.0);
234          }
235 +                                                /* top face */
236 +        printf("\n%s polygon %s.t\n", pmtype, pname);
237 +        printf("0\n0\n%d\n", nverts*3);
238 +        for (i = nverts; i--; ) {
239 +                printf("\t%18.12g\t%18.12g\t%18.12g\n",
240 +                vert[i][0] + lvect[0] + crad*(a[i]*u[i][0] - u[i][1]),
241 +                vert[i][1] + lvect[1] + crad*(a[i]*u[i][1] + u[i][0]),
242 +                lvect[2]);
243 +        }
244                                                  /* bottom corners and edges */
245          c0[0] = cl[0] = vert[nverts-1][0] +
246                          crad*(a[nverts-1]*u[nverts-1][0] - u[nverts-1][1]);
# Line 236 | Line 255 | printrends()                   /* print ends of prism with rounding */
255                  } else {
256                          c1[0] = cl[0]; c1[1] = cl[1]; c1[2] = cl[2];
257                  }
258 <                if (a[i] > 0.) {
258 >                if (lvdir*a[i] > 0.) {
259                          printf("\n%s sphere %s.bc%d\n", pmtype, pname, i+1);
260                          printf("0\n0\n4 %18.12g %18.12g %18.12g %18.12g\n",
261 <                                c1[0], c1[1], c1[2], crad);
261 >                                c1[0], c1[1], c1[2], lvdir*crad);
262                  }
263                  printf("\n%s cylinder %s.be%d\n", pmtype, pname, i+1);
264                  printf("0\n0\n7\n");
265                  printf("\t%18.12g\t%18.12g\t%18.12g\n", c0[0], c0[1], c0[2]);
266                  printf("\t%18.12g\t%18.12g\t%18.12g\n", c1[0], c1[1], c1[2]);
267 <                printf("\t%18.12g\n", crad);
267 >                printf("\t%18.12g\n", lvdir*crad);
268                  c0[0] = c1[0]; c0[1] = c1[1]; c0[2] = c1[2];
269          }
251                                                /* top face */
252        printf("\n%s polygon %s.t\n", pmtype, pname);
253        printf("0\n0\n%d\n", nverts*3);
254        for (i = nverts; i--; ) {
255                printf("\t%18.12g\t%18.12g\t%18.12g\n",
256                vert[i][0] + lvect[0] + crad*(a[i]*u[i][0] - u[i][1]),
257                vert[i][1] + lvect[1] + crad*(a[i]*u[i][1] + u[i][0]),
258                lvect[2]);
259        }
270                                                  /* top corners and edges */
271          c0[0] = cl[0] = vert[nverts-1][0] + lvect[0] +
272                          crad*(a[nverts-1]*u[nverts-1][0] - u[nverts-1][1]);
# Line 273 | Line 283 | printrends()                   /* print ends of prism with rounding */
283                  } else {
284                          c1[0] = cl[0]; c1[1] = cl[1]; c1[2] = cl[2];
285                  }
286 <                if (a[i] > 0.) {
286 >                if (lvdir*a[i] > 0.) {
287                          printf("\n%s sphere %s.tc%d\n", pmtype, pname, i+1);
288                          printf("0\n0\n4 %18.12g %18.12g %18.12g %18.12g\n",
289 <                                c1[0], c1[1], c1[2], crad);
289 >                                c1[0], c1[1], c1[2], lvdir*crad);
290                  }
291                  printf("\n%s cylinder %s.te%d\n", pmtype, pname, i+1);
292                  printf("0\n0\n7\n");
293                  printf("\t%18.12g\t%18.12g\t%18.12g\n", c0[0], c0[1], c0[2]);
294                  printf("\t%18.12g\t%18.12g\t%18.12g\n", c1[0], c1[1], c1[2]);
295 <                printf("\t%18.12g\n", crad);
295 >                printf("\t%18.12g\n", lvdir*crad);
296                  c0[0] = c1[0]; c0[1] = c1[1]; c0[2] = c1[2];
297          }
298   }
# Line 328 | Line 338 | register int  n0, n1;
338          double  s, c, t[3];
339  
340                                          /* compute tanget offset vector */
341 <        s = (lvect[1]*u[n1][0] - lvect[0]*u[n1][1])/llen;
341 >        s = lvdir*(lvect[1]*u[n1][0] - lvect[0]*u[n1][1])/llen;
342          if (s < -FTINY || s > FTINY) {
343                  c = sqrt(1. - s*s);
344                  t[0] = (c - 1.)*u[n1][1];
# Line 356 | Line 366 | register int  n0, n1;
366                          vert[n1][1] + crad*(t[1] + a[n1]*u[n1][1]),
367                          crad*(t[2] + 1.));
368                                          /* output joining edge */
369 <        if (a[n1] < 0.)
369 >        if (lvdir*a[n1] < 0.)
370                  return;
371          printf("\n%s cylinder %s.e%d\n", pmtype, pname, n0+1);
372          printf("0\n0\n7\n");
# Line 368 | Line 378 | register int  n0, n1;
378                  vert[n1][0] + lvect[0] + crad*(a[n1]*u[n1][0] - u[n1][1]),
379                  vert[n1][1] + lvect[1] + crad*(a[n1]*u[n1][1] + u[n1][0]),
380                  lvect[2] - crad);
381 <        printf("\t%18.12g\n", crad);
381 >        printf("\t%18.12g\n", lvdir*crad);
382   }
383  
384  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines