ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genblinds.c
Revision: 2.10
Committed: Sun Jun 8 12:03:09 2003 UTC (20 years, 10 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.9: +57 -52 lines
Log Message:
Reduced compile warnings/errors on Windows.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: genblinds.c,v 2.9 2003/02/22 02:07:23 greg Exp $";
3 #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 #include <stdlib.h>
20 #include <math.h>
21 #include <string.h>
22
23 #define PI 3.14159265358979323846
24 #define DELTA 10. /* MINIMAL SUSTAINED ANGLE IN DEGREES */
25
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
32
33
34 makeflat(w,d,a)
35 double w, d, a;
36 {
37 double h;
38
39 h = d*sin(a);
40 d *= cos(a);
41 baseflat[0][0] = 0.0;
42 baseflat[0][1] = 0.0;
43 baseflat[0][2] = 0.0;
44 baseflat[1][0] = 0.0;
45 baseflat[1][1] = w;
46 baseflat[1][2] = 0.0;
47 baseflat[2][0] = d;
48 baseflat[2][1] = w;
49 baseflat[2][2] = h;
50 baseflat[3][0] = d;
51 baseflat[3][1] = 0.0;
52 baseflat[3][2] = h;
53
54 }
55
56
57 printslat(n) /* print slat # n */
58 int n;
59 {
60 register int i, k;
61
62 for (k=0; k < nsurf; k++) {
63 printf("\n%s polygon %s.%d.%d\n", material, name, n, k);
64 printf("0\n0\n12\n");
65 for (i = 0; i < 4; i++)
66 printf("\t%18.12g\t%18.12g\t%18.12g\n",
67 baseblind[i][0][k],
68 baseblind[i][1][k],
69 baseblind[i][2][k] + height*(n-.5)/nslats);
70 }
71 }
72
73
74 printhead(ac, av) /* print command header */
75 register int ac;
76 register char **av;
77 {
78 putchar('#');
79 while (ac--) {
80 putchar(' ');
81 fputs(*av++, stdout);
82 }
83 putchar('\n');
84 }
85
86
87 main(argc, argv)
88 int argc;
89 char *argv[];
90 {
91 double width, delem, depth, rcurv = 0.0, angle;
92 double beta, gamma, theta, chi;
93 int i, j, k, l;
94
95
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
117 /* BLINDS SUSTAINED ANGLE */
118
119 theta = 2*asin(depth/(2*fabs(rcurv)));
120
121 /* HOW MANY ELEMENTARY SURFACES SHOULD BE CALCULATED ? */
122
123 nsurf = (int)(theta / ((PI/180.)*DELTA)) + 1;
124
125 /* WHAT IS THE DEPTH OF THE ELEMENTARY SURFACES ? */
126
127 delem = 2*fabs(rcurv)*sin((PI/180.)*(DELTA/2.));
128
129 beta = (PI-theta)/2.;
130 gamma = beta -((PI/180.)*angle);
131
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);
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;
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];
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];
163 X[1]=0.;
164 X[2]=(-fabs(rcurv))*sin(gamma+theta-(k*(PI/180.)*DELTA))-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 }
173 }
174
175 /* FLAT BLINDS CALCULATION */
176
177 if (rcurv == 0.) {
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 }
187
188 printhead(argc, argv);
189
190
191 /* REPEAT THE BASIC CURVED OR FLAT SLAT TO GET THE OVERALL BLIND */
192
193 for (l = 1; l <= nslats; l++)
194 printslat(l);
195 exit(0);
196 userr:
197 fprintf(stderr,
198 "Usage: %s mat name depth width height nslats angle [-r|+r rcurv]\n",
199 argv[0]);
200 exit(1);
201 }
202
203
204