1 |
– |
/* Copyright (c) 1986 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* genblind2.c - make some curved or flat venetian blinds. |
6 |
|
* |
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 */ |
24 |
> |
#define DELTA 3. /* MINIMAL SUSTAINED ANGLE IN DEGREES */ |
25 |
|
|
26 |
|
double baseflat[4][3], baseblind[4][3][180]; |
27 |
|
double A[3],X[3]; |
29 |
|
double height; |
30 |
|
int nslats, nsurf; |
31 |
|
|
33 |
– |
#ifdef DCL_ATOF |
34 |
– |
extern double atof(); |
35 |
– |
#endif |
32 |
|
|
33 |
+ |
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 |
|
|
38 |
– |
main(argc, argv) |
39 |
– |
int argc; |
40 |
– |
char *argv[]; |
41 |
– |
{ |
42 |
– |
double width, delem, depth, rcurv = 0.0, angle; |
43 |
– |
double beta, gamma, theta, chi; |
44 |
– |
int i, j, k, l; |
37 |
|
|
38 |
< |
|
39 |
< |
if (argc != 8 && argc != 10) |
40 |
< |
goto userr; |
41 |
< |
material = argv[1]; |
42 |
< |
name = argv[2]; |
43 |
< |
depth = atof(argv[3]); |
52 |
< |
width = atof(argv[4]); |
53 |
< |
height = atof(argv[5]); |
54 |
< |
nslats = atoi(argv[6]); |
55 |
< |
angle = atof(argv[7]); |
56 |
< |
if (argc == 10) |
57 |
< |
if (!strcmp(argv[8], "-r")) |
58 |
< |
rcurv = atof(argv[9]); |
59 |
< |
else if (!strcmp(argv[8], "+r")) |
60 |
< |
rcurv = -atof(argv[9]); |
61 |
< |
else |
62 |
< |
goto userr; |
63 |
< |
|
64 |
< |
/* CURVED BLIND CALCULATION */ |
65 |
< |
|
66 |
< |
if (rcurv != 0) { |
67 |
< |
|
68 |
< |
/* BLINDS SUSTAINED ANGLE */ |
69 |
< |
|
70 |
< |
theta = 2*asin(depth/(2*fabs(rcurv))); |
71 |
< |
|
72 |
< |
/* HOW MANY ELEMENTARY SURFACES SHOULD BE CALCULATED ? */ |
73 |
< |
|
74 |
< |
nsurf = (theta / ((PI/180.)*DELTA)); |
75 |
< |
|
76 |
< |
/* WHAT IS THE DEPTH OF THE ELEMENTARY SURFACES ? */ |
77 |
< |
|
78 |
< |
delem = 2*fabs(rcurv)*sin((PI/180.)*(DELTA/2.)); |
79 |
< |
|
80 |
< |
beta = (PI-theta)/2.; |
81 |
< |
gamma = beta -((PI/180.)*angle); |
82 |
< |
|
83 |
< |
|
84 |
< |
|
85 |
< |
if (rcurv < 0) { |
86 |
< |
A[0]=fabs(rcurv)*cos(gamma); |
87 |
< |
A[0] *= -1; |
88 |
< |
A[1]=0.; |
89 |
< |
A[2]=fabs(rcurv)*sin(gamma); |
90 |
< |
} |
91 |
< |
if (rcurv > 0) { |
92 |
< |
A[0]=fabs(rcurv)*cos(gamma+theta); |
93 |
< |
A[1]=0.; |
94 |
< |
A[2]=fabs(rcurv)*sin(gamma+theta); |
95 |
< |
A[2] *= -1; |
96 |
< |
} |
97 |
< |
|
98 |
< |
for (k=0; k < nsurf; k++) { |
99 |
< |
if (rcurv < 0) { |
100 |
< |
chi=(PI/180.)*((180.-DELTA)/2.) - (gamma+(k*(PI/180.)*DELTA)); |
101 |
< |
} |
102 |
< |
if (rcurv > 0) { |
103 |
< |
chi=(PI-(gamma+theta)+(k*(PI/180.)*DELTA))-(PI/180.)* |
104 |
< |
((180.-DELTA)/2.); |
105 |
< |
} |
106 |
< |
makeflat(width, delem, chi); |
107 |
< |
if (rcurv < 0.) { |
108 |
< |
X[0]=(-fabs(rcurv))*cos(gamma+(k*(PI/180.)*DELTA))-A[0]; |
109 |
< |
X[1]=0.; |
110 |
< |
X[2]=fabs(rcurv)*sin(gamma+(k*(PI/180.)*DELTA))-A[2]; |
111 |
< |
} |
112 |
< |
if (rcurv > 0.) { |
113 |
< |
X[0]=fabs(rcurv)*cos(gamma+theta-(k*(PI/180.)*DELTA))-A[0]; |
114 |
< |
X[1]=0.; |
115 |
< |
X[2]=(-fabs(rcurv))*sin(gamma+theta-(k*(PI/180.)*DELTA))-A[2]; |
116 |
< |
} |
117 |
< |
|
118 |
< |
for (i=0; i < 4; i++) { |
119 |
< |
for (j=0; j < 3; j++) { |
120 |
< |
baseblind[i][j][k] = baseflat[i][j]+X[j]; |
121 |
< |
} |
122 |
< |
} |
123 |
< |
} |
124 |
< |
} |
125 |
< |
|
126 |
< |
/* FLAT BLINDS CALCULATION */ |
127 |
< |
|
128 |
< |
if (rcurv == 0.) { |
129 |
< |
|
130 |
< |
nsurf=1; |
131 |
< |
makeflat(width,depth,angle*(PI/180.)); |
132 |
< |
for (i=0; i < 4; i++) { |
133 |
< |
for (j=0; j < 3; j++) { |
134 |
< |
baseblind[i][j][0] = baseflat[i][j]; |
135 |
< |
} |
136 |
< |
} |
137 |
< |
} |
138 |
< |
|
139 |
< |
printhead(argc, argv); |
140 |
< |
|
141 |
< |
|
142 |
< |
/* REPEAT THE BASIC CURVED OR FLAT SLAT TO GET THE OVERALL BLIND */ |
143 |
< |
|
144 |
< |
for (l = 1; l <= nslats; l++) |
145 |
< |
printslat(l); |
146 |
< |
exit(0); |
147 |
< |
userr: |
148 |
< |
fprintf(stderr, |
149 |
< |
"Usage: %s mat name depth width height nslats angle [-r|+r rcurv]\n", |
150 |
< |
argv[0]); |
151 |
< |
exit(1); |
152 |
< |
} |
153 |
< |
|
154 |
< |
|
155 |
< |
makeflat(w,d,a) |
156 |
< |
double w, d, a; |
38 |
> |
void |
39 |
> |
makeflat( |
40 |
> |
double w, |
41 |
> |
double d, |
42 |
> |
double a |
43 |
> |
) |
44 |
|
{ |
45 |
|
double h; |
46 |
|
|
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
< |
printslat(n) /* print slat # n */ |
66 |
< |
int n; |
65 |
> |
void |
66 |
> |
printslat( /* print slat # n */ |
67 |
> |
int n |
68 |
> |
) |
69 |
|
{ |
70 |
|
register int i, k; |
71 |
|
|
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
< |
printhead(ac, av) /* print command header */ |
85 |
< |
register int ac; |
86 |
< |
register char **av; |
84 |
> |
void |
85 |
> |
printhead( /* print command header */ |
86 |
> |
register int ac, |
87 |
> |
register char **av |
88 |
> |
) |
89 |
|
{ |
90 |
|
putchar('#'); |
91 |
|
while (ac--) { |
94 |
|
} |
95 |
|
putchar('\n'); |
96 |
|
} |
97 |
+ |
|
98 |
+ |
|
99 |
+ |
int |
100 |
+ |
main( |
101 |
+ |
int argc, |
102 |
+ |
char *argv[] |
103 |
+ |
) |
104 |
+ |
{ |
105 |
+ |
double width, delem, depth, rcurv = 0.0, mydelta, angle; |
106 |
+ |
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 |
+ |
} |
127 |
+ |
/* CURVED BLIND CALCULATION */ |
128 |
+ |
|
129 |
+ |
if (rcurv != 0.) { |
130 |
+ |
|
131 |
+ |
/* BLINDS SUSTAINED ANGLE */ |
132 |
+ |
|
133 |
+ |
theta = 2.*asin(depth/(2.*fabs(rcurv))); |
134 |
+ |
|
135 |
+ |
/* HOW MANY ELEMENTARY SURFACES SHOULD BE CALCULATED ? */ |
136 |
+ |
|
137 |
+ |
nsurf = (int)(theta / ((PI/180.)*DELTA) + 0.99999); |
138 |
+ |
|
139 |
+ |
mydelta = (180./PI) * theta / nsurf; |
140 |
+ |
|
141 |
+ |
/* WHAT IS THE DEPTH OF THE ELEMENTARY SURFACES ? */ |
142 |
+ |
|
143 |
+ |
delem = 2.*fabs(rcurv)*sin((PI/180.)*(mydelta/2.)); |
144 |
+ |
|
145 |
+ |
beta = (PI-theta)/2.; |
146 |
+ |
gamma = beta -((PI/180.)*angle); |
147 |
+ |
|
148 |
+ |
|
149 |
+ |
|
150 |
+ |
if (rcurv < 0) { |
151 |
+ |
A[0]=fabs(rcurv)*cos(gamma); |
152 |
+ |
A[0] *= -1.; |
153 |
+ |
A[1]=0.; |
154 |
+ |
A[2]=fabs(rcurv)*sin(gamma); |
155 |
+ |
} |
156 |
+ |
if (rcurv > 0) { |
157 |
+ |
A[0]=fabs(rcurv)*cos(gamma+theta); |
158 |
+ |
A[1]=0.; |
159 |
+ |
A[2]=fabs(rcurv)*sin(gamma+theta); |
160 |
+ |
A[2] *= -1.; |
161 |
+ |
} |
162 |
+ |
|
163 |
+ |
for (k=0; k < nsurf; k++) { |
164 |
+ |
if (rcurv < 0) { |
165 |
+ |
chi=(PI/180.)*((180.-mydelta)/2.) - (gamma+(k*(PI/180.)*mydelta)); |
166 |
+ |
} |
167 |
+ |
if (rcurv > 0) { |
168 |
+ |
chi=(PI-(gamma+theta)+(k*(PI/180.)*mydelta))-(PI/180.)* |
169 |
+ |
((180.-mydelta)/2.); |
170 |
+ |
} |
171 |
+ |
makeflat(width, delem, chi); |
172 |
+ |
if (rcurv < 0.) { |
173 |
+ |
X[0]=(-fabs(rcurv))*cos(gamma+(k*(PI/180.)*mydelta))-A[0]; |
174 |
+ |
X[1]=0.; |
175 |
+ |
X[2]=fabs(rcurv)*sin(gamma+(k*(PI/180.)*mydelta))-A[2]; |
176 |
+ |
} |
177 |
+ |
if (rcurv > 0.) { |
178 |
+ |
X[0]=fabs(rcurv)*cos(gamma+theta-(k*(PI/180.)*mydelta))-A[0]; |
179 |
+ |
X[1]=0.; |
180 |
+ |
X[2]=(-fabs(rcurv))*sin(gamma+theta-(k*(PI/180.)*mydelta))-A[2]; |
181 |
+ |
} |
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 |
+ |
} |
189 |
+ |
} |
190 |
+ |
|
191 |
+ |
/* FLAT BLINDS CALCULATION */ |
192 |
+ |
|
193 |
+ |
else { |
194 |
+ |
|
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 |
+ |
} |
202 |
+ |
} |
203 |
+ |
|
204 |
+ |
printhead(argc, argv); |
205 |
+ |
|
206 |
+ |
|
207 |
+ |
/* REPEAT THE BASIC CURVED OR FLAT SLAT TO GET THE OVERALL BLIND */ |
208 |
+ |
|
209 |
+ |
for (l = 1; l <= nslats; l++) |
210 |
+ |
printslat(l); |
211 |
+ |
exit(0); |
212 |
+ |
userr: |
213 |
+ |
fprintf(stderr, |
214 |
+ |
"Usage: %s mat name depth width height nslats angle [-r|+r rcurv]\n", |
215 |
+ |
argv[0]); |
216 |
+ |
exit(1); |
217 |
+ |
} |
218 |
+ |
|
219 |
+ |
|
220 |
+ |
|