1 |
greg |
1.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 atof(), fabs(); |
39 |
|
|
double width, delem, depth, rcurv = 0.0, angle; |
40 |
|
|
double beta, gamma, theta, chi; |
41 |
|
|
int i, j, k, l; |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
if (argc != 8 && argc != 10) |
45 |
|
|
goto userr; |
46 |
|
|
material = argv[1]; |
47 |
|
|
name = argv[2]; |
48 |
|
|
depth = atof(argv[3]); |
49 |
|
|
width = atof(argv[4]); |
50 |
|
|
height = atof(argv[5]); |
51 |
|
|
nslats = atoi(argv[6]); |
52 |
|
|
angle = atof(argv[7]); |
53 |
|
|
if (argc == 10) |
54 |
|
|
if (!strcmp(argv[8], "-r")) |
55 |
|
|
rcurv = atof(argv[8]); |
56 |
|
|
else if (!strcmp(argv[8], "+r")) |
57 |
|
|
rcurv = -atof(argv[8]); |
58 |
|
|
else |
59 |
|
|
goto userr; |
60 |
|
|
|
61 |
|
|
/* CURVED BLIND CALCULATION */ |
62 |
|
|
|
63 |
|
|
if (rcurv != 0) { |
64 |
|
|
|
65 |
|
|
/* BLINDS SUSTAINED ANGLE */ |
66 |
|
|
|
67 |
|
|
theta = 2*asin(depth/(2*fabs(rcurv))); |
68 |
|
|
|
69 |
|
|
/* HOW MANY ELEMENTARY SURFACES SHOULD BE CALCULATED ? */ |
70 |
|
|
|
71 |
|
|
nsurf = (theta / ((PI/180.)*DELTA)); |
72 |
|
|
|
73 |
|
|
/* WHAT IS THE DEPTH OF THE ELEMENTARY SURFACES ? */ |
74 |
|
|
|
75 |
|
|
delem = 2*fabs(rcurv)*sin((PI/180.)*(DELTA/2.)); |
76 |
|
|
|
77 |
|
|
beta = (PI-theta)/2.; |
78 |
|
|
gamma = beta -((PI/180.)*angle); |
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
if (rcurv < 0) { |
83 |
|
|
A[0]=fabs(rcurv)*cos(gamma); |
84 |
|
|
A[0] *= -1; |
85 |
|
|
A[1]=0.; |
86 |
|
|
A[2]=fabs(rcurv)*sin(gamma); |
87 |
|
|
} |
88 |
|
|
if (rcurv > 0) { |
89 |
|
|
A[0]=fabs(rcurv)*cos(gamma+theta); |
90 |
|
|
A[1]=0.; |
91 |
|
|
A[2]=fabs(rcurv)*sin(gamma+theta); |
92 |
|
|
A[2] *= -1; |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
for (k=0; k < nsurf; k++) { |
96 |
|
|
if (rcurv < 0) { |
97 |
|
|
chi=(PI/180.)*((180.-DELTA)/2.) - (gamma+(k*(PI/180.)*DELTA)); |
98 |
|
|
} |
99 |
|
|
if (rcurv > 0) { |
100 |
|
|
chi=(PI-(gamma+theta)+(k*(PI/180.)*DELTA))-(PI/180.)* |
101 |
|
|
((180.-DELTA)/2.); |
102 |
|
|
} |
103 |
|
|
makeflat(width, delem, chi); |
104 |
|
|
if (rcurv < 0.) { |
105 |
|
|
X[0]=(-fabs(rcurv))*cos(gamma+(k*(PI/180.)*DELTA))-A[0]; |
106 |
|
|
X[1]=0.; |
107 |
|
|
X[2]=fabs(rcurv)*sin(gamma+(k*(PI/180.)*DELTA))-A[2]; |
108 |
|
|
} |
109 |
|
|
if (rcurv > 0.) { |
110 |
|
|
X[0]=fabs(rcurv)*cos(gamma+theta-(k*(PI/180.)*DELTA))-A[0]; |
111 |
|
|
X[1]=0.; |
112 |
|
|
X[2]=(-fabs(rcurv))*sin(gamma+theta-(k*(PI/180.)*DELTA))-A[2]; |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
for (i=0; i < 4; i++) { |
116 |
|
|
for (j=0; j < 3; j++) { |
117 |
|
|
baseblind[i][j][k] = baseflat[i][j]+X[j]; |
118 |
|
|
} |
119 |
|
|
} |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
/* FLAT BLINDS CALCULATION */ |
124 |
|
|
|
125 |
|
|
if (rcurv == 0.) { |
126 |
|
|
|
127 |
|
|
nsurf=1; |
128 |
|
|
makeflat(width,depth,angle*(PI/180.)); |
129 |
|
|
for (i=0; i < 4; i++) { |
130 |
|
|
for (j=0; j < 3; j++) { |
131 |
|
|
baseblind[i][j][0] = baseflat[i][j]; |
132 |
|
|
} |
133 |
|
|
} |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
printhead(argc, argv); |
137 |
|
|
|
138 |
|
|
|
139 |
|
|
/* REPEAT THE BASIC CURVED OR FLAT SLAT TO GET THE OVERALL BLIND */ |
140 |
|
|
|
141 |
|
|
for (l = 1; l <= nslats; l++) |
142 |
|
|
printslat(l); |
143 |
|
|
exit(0); |
144 |
|
|
userr: |
145 |
|
|
fprintf(stderr, |
146 |
|
|
"Usage: %s mat name depth width height nslats angle [-r|+r rcurv]\n", |
147 |
|
|
argv[0]); |
148 |
|
|
exit(1); |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
|
152 |
|
|
makeflat(w,d,a) |
153 |
|
|
double w, d, a; |
154 |
|
|
{ |
155 |
|
|
double sin(), cos(); |
156 |
|
|
double h; |
157 |
|
|
|
158 |
|
|
h = d*sin(a); |
159 |
|
|
d *= cos(a); |
160 |
|
|
baseflat[0][0] = 0.0; |
161 |
|
|
baseflat[0][1] = 0.0; |
162 |
|
|
baseflat[0][2] = 0.0; |
163 |
|
|
baseflat[1][0] = 0.0; |
164 |
|
|
baseflat[1][1] = w; |
165 |
|
|
baseflat[1][2] = 0.0; |
166 |
|
|
baseflat[2][0] = d; |
167 |
|
|
baseflat[2][1] = w; |
168 |
|
|
baseflat[2][2] = h; |
169 |
|
|
baseflat[3][0] = d; |
170 |
|
|
baseflat[3][1] = 0.0; |
171 |
|
|
baseflat[3][2] = h; |
172 |
|
|
|
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
|
176 |
|
|
printslat(n) /* print slat # n */ |
177 |
|
|
int n; |
178 |
|
|
{ |
179 |
|
|
register int i, k; |
180 |
|
|
|
181 |
|
|
for (k=0; k < nsurf; k++) { |
182 |
|
|
printf("\n%s polygon %s.%d.%d\n", material, name, n, k); |
183 |
|
|
printf("0\n0\n12\n"); |
184 |
|
|
for (i = 0; i < 4; i++) |
185 |
|
|
printf("\t%18.12g\t%18.12g\t%18.12g\n", |
186 |
|
|
baseblind[i][0][k], |
187 |
|
|
baseblind[i][1][k], |
188 |
|
|
baseblind[i][2][k] + height*(n-.5)/nslats); |
189 |
|
|
} |
190 |
|
|
} |
191 |
|
|
|
192 |
|
|
|
193 |
|
|
printhead(ac, av) /* print command header */ |
194 |
|
|
register int ac; |
195 |
|
|
register char **av; |
196 |
|
|
{ |
197 |
|
|
putchar('#'); |
198 |
|
|
while (ac--) { |
199 |
|
|
putchar(' '); |
200 |
|
|
fputs(*av++, stdout); |
201 |
|
|
} |
202 |
|
|
putchar('\n'); |
203 |
|
|
} |