ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genblinds.c
Revision: 2.12
Committed: Wed Dec 28 19:42:13 2005 UTC (18 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad4R2P2, rad4R2, rad4R1, rad4R0, rad3R8, rad3R9, rad4R2P1
Changes since 2.11: +18 -16 lines
Log Message:
Fixed problems with genblinds

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.12 static const char RCSid[] = "$Id: genblinds.c,v 2.11 2003/11/16 10:29:38 schorsch Exp $";
3 greg 1.1 #endif
4     /*
5     * genblind2.c - make some curved or flat venetian blinds.
6     *
7     * Jean-Louis Scartezzini and Greg Ward
8     *
9     * parameters:
10     * depth - depth of blinds
11     * width - width of slats
12     * height - height of blinds
13     * nslats - number of slats
14     * angle - blind incidence angle ( in degrees )
15     * rcurv - curvature radius of slats (up:>0;down:<0;flat:=0)
16     */
17    
18     #include <stdio.h>
19 greg 2.9 #include <stdlib.h>
20 greg 1.1 #include <math.h>
21 schorsch 2.10 #include <string.h>
22 greg 1.1
23 greg 2.7 #define PI 3.14159265358979323846
24     #define DELTA 10. /* MINIMAL SUSTAINED ANGLE IN DEGREES */
25 greg 1.1
26     double baseflat[4][3], baseblind[4][3][180];
27     double A[3],X[3];
28     char *material, *name;
29     double height;
30     int nslats, nsurf;
31 greg 2.6
32 greg 1.1
33 schorsch 2.11 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 schorsch 2.10
37 schorsch 2.11
38     void
39     makeflat(
40     double w,
41     double d,
42     double a
43     )
44 schorsch 2.10 {
45     double h;
46    
47     h = d*sin(a);
48     d *= cos(a);
49     baseflat[0][0] = 0.0;
50     baseflat[0][1] = 0.0;
51     baseflat[0][2] = 0.0;
52     baseflat[1][0] = 0.0;
53     baseflat[1][1] = w;
54     baseflat[1][2] = 0.0;
55     baseflat[2][0] = d;
56     baseflat[2][1] = w;
57     baseflat[2][2] = h;
58     baseflat[3][0] = d;
59     baseflat[3][1] = 0.0;
60     baseflat[3][2] = h;
61    
62     }
63    
64    
65 schorsch 2.11 void
66     printslat( /* print slat # n */
67     int n
68     )
69 schorsch 2.10 {
70     register int i, k;
71    
72     for (k=0; k < nsurf; k++) {
73     printf("\n%s polygon %s.%d.%d\n", material, name, n, k);
74     printf("0\n0\n12\n");
75     for (i = 0; i < 4; i++)
76     printf("\t%18.12g\t%18.12g\t%18.12g\n",
77     baseblind[i][0][k],
78     baseblind[i][1][k],
79     baseblind[i][2][k] + height*(n-.5)/nslats);
80     }
81     }
82    
83    
84 schorsch 2.11 void
85     printhead( /* print command header */
86     register int ac,
87     register char **av
88     )
89 schorsch 2.10 {
90     putchar('#');
91     while (ac--) {
92     putchar(' ');
93     fputs(*av++, stdout);
94     }
95     putchar('\n');
96     }
97    
98    
99 schorsch 2.11 int
100     main(
101     int argc,
102     char *argv[]
103     )
104 greg 1.1 {
105 greg 2.12 double width, delem, depth, rcurv = 0.0, mydelta, angle;
106 schorsch 2.11 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 greg 1.1
127 schorsch 2.11 /* CURVED BLIND CALCULATION */
128 greg 1.1
129 greg 2.12 if (rcurv != 0.) {
130 greg 1.1
131     /* BLINDS SUSTAINED ANGLE */
132    
133 greg 2.12 theta = 2.*asin(depth/(2.*fabs(rcurv)));
134 greg 1.1
135 schorsch 2.11 /* HOW MANY ELEMENTARY SURFACES SHOULD BE CALCULATED ? */
136 greg 1.1
137 greg 2.12 nsurf = (int)(theta / ((PI/180.)*DELTA) + 0.99999);
138    
139     mydelta = (180./PI) * theta / nsurf;
140 greg 1.1
141     /* WHAT IS THE DEPTH OF THE ELEMENTARY SURFACES ? */
142    
143 greg 2.12 delem = 2.*fabs(rcurv)*sin((PI/180.)*(mydelta/2.));
144 greg 1.1
145     beta = (PI-theta)/2.;
146     gamma = beta -((PI/180.)*angle);
147    
148    
149    
150     if (rcurv < 0) {
151 schorsch 2.11 A[0]=fabs(rcurv)*cos(gamma);
152 greg 2.12 A[0] *= -1.;
153 schorsch 2.11 A[1]=0.;
154     A[2]=fabs(rcurv)*sin(gamma);
155 greg 1.1 }
156     if (rcurv > 0) {
157 schorsch 2.11 A[0]=fabs(rcurv)*cos(gamma+theta);
158     A[1]=0.;
159     A[2]=fabs(rcurv)*sin(gamma+theta);
160 greg 2.12 A[2] *= -1.;
161 greg 1.1 }
162    
163     for (k=0; k < nsurf; k++) {
164 schorsch 2.11 if (rcurv < 0) {
165 greg 2.12 chi=(PI/180.)*((180.-mydelta)/2.) - (gamma+(k*(PI/180.)*mydelta));
166 schorsch 2.11 }
167     if (rcurv > 0) {
168 greg 2.12 chi=(PI-(gamma+theta)+(k*(PI/180.)*mydelta))-(PI/180.)*
169     ((180.-mydelta)/2.);
170 schorsch 2.11 }
171     makeflat(width, delem, chi);
172     if (rcurv < 0.) {
173 greg 2.12 X[0]=(-fabs(rcurv))*cos(gamma+(k*(PI/180.)*mydelta))-A[0];
174 greg 1.1 X[1]=0.;
175 greg 2.12 X[2]=fabs(rcurv)*sin(gamma+(k*(PI/180.)*mydelta))-A[2];
176 schorsch 2.11 }
177     if (rcurv > 0.) {
178 greg 2.12 X[0]=fabs(rcurv)*cos(gamma+theta-(k*(PI/180.)*mydelta))-A[0];
179 greg 1.1 X[1]=0.;
180 greg 2.12 X[2]=(-fabs(rcurv))*sin(gamma+theta-(k*(PI/180.)*mydelta))-A[2];
181 schorsch 2.11 }
182    
183     for (i=0; i < 4; i++) {
184     for (j=0; j < 3; j++) {
185     baseblind[i][j][k] = baseflat[i][j]+X[j];
186     }
187     }
188 greg 1.1 }
189 schorsch 2.11 }
190    
191     /* FLAT BLINDS CALCULATION */
192 greg 1.1
193 greg 2.12 else {
194 schorsch 2.11
195     nsurf=1;
196     makeflat(width,depth,angle*(PI/180.));
197     for (i=0; i < 4; i++) {
198     for (j=0; j < 3; j++) {
199     baseblind[i][j][0] = baseflat[i][j];
200     }
201 greg 1.1 }
202 schorsch 2.11 }
203 greg 1.1
204 schorsch 2.11 printhead(argc, argv);
205 greg 1.1
206    
207 schorsch 2.11 /* REPEAT THE BASIC CURVED OR FLAT SLAT TO GET THE OVERALL BLIND */
208 greg 1.1
209 schorsch 2.11 for (l = 1; l <= nslats; l++)
210     printslat(l);
211     exit(0);
212 greg 1.1 userr:
213 schorsch 2.11 fprintf(stderr,
214     "Usage: %s mat name depth width height nslats angle [-r|+r rcurv]\n",
215     argv[0]);
216     exit(1);
217 greg 1.1 }
218    
219    
220