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