ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genblinds.c
(Generate patch)

Comparing ray/src/gen/genblinds.c (file contents):
Revision 2.1 by greg, Tue Nov 12 17:04:36 1991 UTC vs.
Revision 2.15 by greg, Sat Jul 25 19:23:09 2020 UTC

# Line 1 | Line 1
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   *
# Line 18 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
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 < #define  PI             3.141592653589793
23 < #define  DELTA          5.  /*  MINIMAL SUSTAINED ANGLE IN DEGREES */
22 > #ifndef PI
23 > #define  PI             3.14159265358979323846
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];
# Line 31 | Line 31 | double  height;
31   int  nslats,  nsurf;
32  
33  
34 < main(argc, argv)
35 < int  argc;
36 < char  *argv[];
34 > static void makeflat(double w, double d, double a);
35 > static void printslat(int n);
36 >
37 > void
38 > makeflat(
39 >        double w,
40 >        double d,
41 >        double a
42 > )
43   {
44 <        double  atof(), fabs();
39 <        double  width, delem, depth, rcurv = 0.0, angle;
40 <        double  beta, gamma, theta, chi;
41 <        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)
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;
61 > }
62  
61 /* 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);
# Line 80 | Line 132 | char  *argv[];
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 <                }      
120 <        }
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 */
124 <        
125 <        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 <        
136 <        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  
152 makeflat(w,d,a)
153 double  w, d, a;
154 {
155        double  sin(), cos();
156        double  h;
205  
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 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines