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.3 by greg, Thu Aug 27 13:51:59 1992 UTC vs.
Revision 2.11 by schorsch, Sun Nov 16 10:29:38 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines