ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genblinds.c
Revision: 2.5
Committed: Fri Jun 4 14:29:34 1993 UTC (30 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.4: +0 -4 lines
Log Message:
Removed unnecessary declaration of atof()

File Contents

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