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

Comparing ray/src/gen/genblinds.c (file contents):
Revision 2.10 by schorsch, Sun Jun 8 12:03:09 2003 UTC vs.
Revision 2.15 by greg, Sat Jul 25 19:23:09 2020 UTC

# Line 15 | Line 15 | static const char      RCSid[] = "$Id$";
15   *              rcurv  -  curvature radius of slats (up:>0;down:<0;flat:=0)
16   */
17  
18 < #include  <stdio.h>
19 < #include <stdlib.h>
18 > #include  "rtio.h"
19 > #include  <stdlib.h>
20   #include  <math.h>
21 #include  <string.h>
21  
22 + #ifndef PI
23   #define  PI             3.14159265358979323846
24 < #define  DELTA          10.  /*  MINIMAL SUSTAINED ANGLE IN DEGREES */
24 > #endif
25 > #define  DELTA          3.  /*  MINIMAL SUSTAINED ANGLE IN DEGREES */
26  
27   double  baseflat[4][3], baseblind[4][3][180];
28   double  A[3],X[3];
# Line 30 | Line 31 | double  height;
31   int  nslats,  nsurf;
32  
33  
34 + static void makeflat(double w, double d, double a);
35 + static void printslat(int n);
36  
37 < makeflat(w,d,a)
38 < double  w, d, a;
37 > void
38 > makeflat(
39 >        double w,
40 >        double d,
41 >        double a
42 > )
43   {
44          double  h;
45  
# Line 54 | Line 61 | double  w, d, a;
61   }
62  
63  
64 < printslat(n)                    /* print slat # n */
65 < int  n;
64 > void
65 > printslat(                      /* print slat # n */
66 >        int  n
67 > )
68   {
69 <        register int  i, k;
69 >        int  i, k;
70  
71          for (k=0; k < nsurf; k++)  {
72                  printf("\n%s polygon %s.%d.%d\n", material, name, n, k);
# Line 71 | Line 80 | int  n;
80   }
81  
82  
83 < printhead(ac, av)               /* print command header */
84 < register int  ac;
85 < register char  **av;
83 > int
84 > main(
85 >        int  argc,
86 >        char  *argv[]
87 > )
88   {
89 <        putchar('#');
90 <        while (ac--) {
91 <                putchar(' ');
81 <                fputs(*av++, stdout);
82 <        }
83 <        putchar('\n');
84 < }
89 >    double  width, delem, depth, rcurv = 0.0, mydelta, angle;
90 >    double  beta, gamma, theta, chi = 0;
91 >    int     i, j, k, l;
92  
93  
94 < main(argc, argv)
95 < int  argc;
96 < char  *argv[];
97 < {
98 <        double  width, delem, depth, rcurv = 0.0, angle;
99 <        double  beta, gamma, theta, chi;
100 <        int     i, j, k, l;
94 >    if (argc != 8 && argc != 10)
95 >        goto userr;
96 >    material = argv[1];
97 >    name = argv[2];
98 >    depth = atof(argv[3]);
99 >    width = atof(argv[4]);
100 >    height = atof(argv[5]);
101 >    nslats  = atoi(argv[6]);
102 >    angle = atof(argv[7]);
103 >    if (argc == 10) {
104 >        if (!strcmp(argv[8], "-r"))
105 >            rcurv = atof(argv[9]);
106 >        else if (!strcmp(argv[8], "+r"))
107 >            rcurv = -atof(argv[9]);
108 >        else
109 >            goto userr;
110 >    }
111 >    /* CURVED BLIND CALCULATION */
112  
113 +    if (rcurv != 0.) {
114  
96        if (argc != 8 && argc != 10)
97                goto userr;
98        material = argv[1];
99        name = argv[2];
100        depth = atof(argv[3]);
101        width = atof(argv[4]);
102        height = atof(argv[5]);
103        nslats  = atoi(argv[6]);
104        angle = atof(argv[7]);
105        if (argc == 10)
106                if (!strcmp(argv[8], "-r"))
107                        rcurv = atof(argv[9]);
108                else if (!strcmp(argv[8], "+r"))
109                        rcurv = -atof(argv[9]);
110                else
111                        goto userr;
112
113 /* CURVED BLIND CALCULATION */
114
115        if (rcurv != 0) {
116
115          /* BLINDS SUSTAINED ANGLE */
116  
117 <        theta = 2*asin(depth/(2*fabs(rcurv)));
117 >        theta = 2.*asin(depth/(2.*fabs(rcurv)));
118  
119 <        /* HOW MANY ELEMENTARY SURFACES SHOULD BE CALCULATED ? */
119 >        /* HOW MANY ELEMENTARY SURFACES SHOULD BE CALCULATED ? */
120  
121 <        nsurf = (int)(theta / ((PI/180.)*DELTA)) + 1;
121 >        nsurf = (int)(theta / ((PI/180.)*DELTA) + 0.99999);
122 >        
123 >        mydelta = (180./PI) * theta / nsurf;
124  
125          /* WHAT IS THE DEPTH OF THE ELEMENTARY SURFACES ? */
126  
127 <        delem = 2*fabs(rcurv)*sin((PI/180.)*(DELTA/2.));
127 >        delem = 2.*fabs(rcurv)*sin((PI/180.)*(mydelta/2.));
128  
129          beta = (PI-theta)/2.;
130          gamma = beta -((PI/180.)*angle);
# Line 132 | Line 132 | char  *argv[];
132  
133  
134          if (rcurv < 0) {
135 <                A[0]=fabs(rcurv)*cos(gamma);
136 <                A[0] *= -1;
137 <                A[1]=0.;
138 <                A[2]=fabs(rcurv)*sin(gamma);
135 >            A[0]=fabs(rcurv)*cos(gamma);
136 >            A[0] *= -1.;
137 >            A[1]=0.;
138 >            A[2]=fabs(rcurv)*sin(gamma);
139          }
140          if (rcurv > 0) {
141 <                A[0]=fabs(rcurv)*cos(gamma+theta);
142 <                A[1]=0.;
143 <                A[2]=fabs(rcurv)*sin(gamma+theta);
144 <                A[2] *= -1;
141 >            A[0]=fabs(rcurv)*cos(gamma+theta);
142 >            A[1]=0.;
143 >            A[2]=fabs(rcurv)*sin(gamma+theta);
144 >            A[2] *= -1.;
145          }
146  
147          for (k=0; k < nsurf; k++) {
148 <        if (rcurv < 0) {
149 <        chi=(PI/180.)*((180.-DELTA)/2.) - (gamma+(k*(PI/180.)*DELTA));
150 <        }
151 <        if (rcurv > 0) {
152 <        chi=(PI-(gamma+theta)+(k*(PI/180.)*DELTA))-(PI/180.)*  
153 <        ((180.-DELTA)/2.);
154 <        }
155 <                makeflat(width, delem, chi);
156 <        if (rcurv < 0.) {
157 <                X[0]=(-fabs(rcurv))*cos(gamma+(k*(PI/180.)*DELTA))-A[0];
148 >            if (rcurv < 0) {
149 >                chi=(PI/180.)*((180.-mydelta)/2.) - (gamma+(k*(PI/180.)*mydelta));
150 >            }
151 >            if (rcurv > 0) {
152 >                chi=(PI-(gamma+theta)+(k*(PI/180.)*mydelta))-(PI/180.)*  
153 >                    ((180.-mydelta)/2.);
154 >            }
155 >            makeflat(width, delem, chi);
156 >            if (rcurv < 0.) {
157 >                X[0]=(-fabs(rcurv))*cos(gamma+(k*(PI/180.)*mydelta))-A[0];
158                  X[1]=0.;
159 <                X[2]=fabs(rcurv)*sin(gamma+(k*(PI/180.)*DELTA))-A[2];
160 <        }
161 <        if (rcurv > 0.) {
162 <                X[0]=fabs(rcurv)*cos(gamma+theta-(k*(PI/180.)*DELTA))-A[0];
159 >                X[2]=fabs(rcurv)*sin(gamma+(k*(PI/180.)*mydelta))-A[2];
160 >            }
161 >            if (rcurv > 0.) {
162 >                X[0]=fabs(rcurv)*cos(gamma+theta-(k*(PI/180.)*mydelta))-A[0];
163                  X[1]=0.;
164 <                X[2]=(-fabs(rcurv))*sin(gamma+theta-(k*(PI/180.)*DELTA))-A[2];
165 <        }
164 >                X[2]=(-fabs(rcurv))*sin(gamma+theta-(k*(PI/180.)*mydelta))-A[2];
165 >            }
166  
167 <                for (i=0; i < 4; i++)  {
168 <                    for (j=0; j < 3; j++) {
169 <                        baseblind[i][j][k] = baseflat[i][j]+X[j];
170 <                    }
171 <                }      
172 <        }
167 >            for (i=0; i < 4; i++)  {
168 >                for (j=0; j < 3; j++) {
169 >                    baseblind[i][j][k] = baseflat[i][j]+X[j];
170 >                }
171 >            }  
172          }
173 +    }
174  
175 < /* FLAT BLINDS CALCULATION */
176 <        
177 <        if (rcurv == 0.) {
175 >    /* FLAT BLINDS CALCULATION */
176  
177 <                nsurf=1;
178 <                makeflat(width,depth,angle*(PI/180.));
179 <                for (i=0; i < 4; i++) {
180 <                    for (j=0; j < 3; j++) {
181 <                        baseblind[i][j][0] = baseflat[i][j];
182 <                    }
183 <                }
177 >    else {
178 >
179 >        nsurf=1;
180 >        makeflat(width,depth,angle*(PI/180.));
181 >        for (i=0; i < 4; i++) {
182 >            for (j=0; j < 3; j++) {
183 >                baseblind[i][j][0] = baseflat[i][j];
184 >            }
185          }
186 <        
188 <        printhead(argc, argv);
186 >    }
187  
188 +    fputs("# ", stdout);
189 +    printargs(argc, argv, stdout);
190 +
191  
192 < /* REPEAT THE BASIC CURVED OR FLAT SLAT TO GET THE OVERALL BLIND */
192 >    /* REPEAT THE BASIC CURVED OR FLAT SLAT TO GET THE OVERALL BLIND */
193  
194 <        for (l = 1; l <= nslats; l++)
195 <                printslat(l);
196 <        exit(0);
194 >    for (l = 1; l <= nslats; l++)
195 >        printslat(l);
196 >    exit(0);
197   userr:
198 <        fprintf(stderr,
199 <        "Usage: %s mat name depth width height nslats angle [-r|+r rcurv]\n",
200 <                        argv[0]);
201 <        exit(1);
198 >    fprintf(stderr,
199 >            "Usage: %s mat name depth width height nslats angle [-r|+r rcurv]\n",
200 >            argv[0]);
201 >    exit(1);
202   }
203  
204  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines