ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genblinds.c
Revision: 2.6
Committed: Mon Aug 2 14:22:58 1993 UTC (30 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.5: +4 -0 lines
Log Message:
added conditional declaration of atof()

File Contents

# User Rev Content
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 greg 2.6 #ifdef DCL_ATOF
34     extern double atof();
35     #endif
36    
37 greg 1.1
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;
45    
46    
47     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 greg 2.3 rcurv = atof(argv[9]);
59 greg 1.1 else if (!strcmp(argv[8], "+r"))
60 greg 2.3 rcurv = -atof(argv[9]);
61 greg 1.1 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;
157     {
158     double h;
159    
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     }