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