Back to index

radiance  4R0+20100331
genblinds.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: genblinds.c,v 2.12 2005/12/28 19:42:13 greg Exp $";
00003 #endif
00004 /*
00005  *  genblind2.c - make some curved or flat venetian blinds.
00006  *
00007  *     Jean-Louis Scartezzini and Greg Ward
00008  * 
00009  *  parameters: 
00010  *            depth  -  depth of blinds
00011  *            width  -  width of slats
00012  *            height -  height of blinds
00013  *            nslats -  number of slats
00014  *            angle  -  blind incidence angle ( in degrees )
00015  *            rcurv  -  curvature radius of slats (up:>0;down:<0;flat:=0)
00016  */
00017 
00018 #include  <stdio.h>
00019 #include <stdlib.h>
00020 #include  <math.h>
00021 #include  <string.h>
00022 
00023 #define  PI          3.14159265358979323846
00024 #define  DELTA              10.  /*  MINIMAL SUSTAINED ANGLE IN DEGREES */
00025 
00026 double  baseflat[4][3], baseblind[4][3][180];
00027 double  A[3],X[3];
00028 char  *material, *name;
00029 double  height;
00030 int  nslats,  nsurf;
00031 
00032 
00033 static void makeflat(double w, double d, double a);
00034 static void printslat(int n);
00035 static void printhead(register int  ac, register char  **av);
00036 
00037 
00038 void
00039 makeflat(
00040        double w,
00041        double d,
00042        double a
00043 )
00044 {
00045        double  h;
00046 
00047        h = d*sin(a);
00048        d *= cos(a);
00049        baseflat[0][0] = 0.0;
00050        baseflat[0][1] = 0.0;
00051        baseflat[0][2] = 0.0;
00052        baseflat[1][0] = 0.0;
00053        baseflat[1][1] = w;
00054        baseflat[1][2] = 0.0;
00055        baseflat[2][0] = d;
00056        baseflat[2][1] = w;
00057        baseflat[2][2] = h;
00058        baseflat[3][0] = d;
00059        baseflat[3][1] = 0.0;
00060        baseflat[3][2] = h;
00061 
00062 }
00063 
00064 
00065 void
00066 printslat(                  /* print slat # n */
00067        int  n
00068 )
00069 {
00070        register int  i, k;
00071 
00072        for (k=0; k < nsurf; k++)  {
00073               printf("\n%s polygon %s.%d.%d\n", material, name, n, k);
00074               printf("0\n0\n12\n");
00075               for (i = 0; i < 4; i++)
00076                      printf("\t%18.12g\t%18.12g\t%18.12g\n",
00077                             baseblind[i][0][k],
00078                             baseblind[i][1][k],
00079                             baseblind[i][2][k] + height*(n-.5)/nslats);
00080        }             
00081 }
00082 
00083 
00084 void
00085 printhead(           /* print command header */
00086        register int  ac,
00087        register char  **av
00088 )
00089 {
00090        putchar('#');
00091        while (ac--) {
00092               putchar(' ');
00093               fputs(*av++, stdout);
00094        }
00095        putchar('\n');
00096 }
00097 
00098 
00099 int
00100 main(
00101        int  argc,
00102        char  *argv[]
00103 )
00104 {
00105     double  width, delem, depth, rcurv = 0.0, mydelta, angle;
00106     double  beta, gamma, theta, chi = 0;
00107     int     i, j, k, l;
00108 
00109 
00110     if (argc != 8 && argc != 10)
00111        goto userr;
00112     material = argv[1];
00113     name = argv[2];
00114     depth = atof(argv[3]);
00115     width = atof(argv[4]);
00116     height = atof(argv[5]);
00117     nslats  = atoi(argv[6]);
00118     angle = atof(argv[7]);
00119     if (argc == 10)
00120        if (!strcmp(argv[8], "-r"))
00121            rcurv = atof(argv[9]);
00122        else if (!strcmp(argv[8], "+r"))
00123            rcurv = -atof(argv[9]);
00124        else
00125            goto userr;
00126 
00127     /* CURVED BLIND CALCULATION */
00128 
00129     if (rcurv != 0.) {
00130 
00131        /* BLINDS SUSTAINED ANGLE */
00132 
00133        theta = 2.*asin(depth/(2.*fabs(rcurv)));
00134 
00135        /* HOW MANY ELEMENTARY SURFACES SHOULD BE CALCULATED ? */
00136 
00137        nsurf = (int)(theta / ((PI/180.)*DELTA) + 0.99999);
00138        
00139        mydelta = (180./PI) * theta / nsurf;
00140 
00141        /* WHAT IS THE DEPTH OF THE ELEMENTARY SURFACES ? */
00142 
00143        delem = 2.*fabs(rcurv)*sin((PI/180.)*(mydelta/2.));
00144 
00145        beta = (PI-theta)/2.;
00146        gamma = beta -((PI/180.)*angle);
00147 
00148 
00149 
00150        if (rcurv < 0) {
00151            A[0]=fabs(rcurv)*cos(gamma);
00152            A[0] *= -1.;
00153            A[1]=0.;
00154            A[2]=fabs(rcurv)*sin(gamma);
00155        }
00156        if (rcurv > 0) {
00157            A[0]=fabs(rcurv)*cos(gamma+theta);
00158            A[1]=0.;
00159            A[2]=fabs(rcurv)*sin(gamma+theta);
00160            A[2] *= -1.;
00161        }
00162 
00163        for (k=0; k < nsurf; k++) {
00164            if (rcurv < 0) {
00165               chi=(PI/180.)*((180.-mydelta)/2.) - (gamma+(k*(PI/180.)*mydelta));
00166            }
00167            if (rcurv > 0) {
00168               chi=(PI-(gamma+theta)+(k*(PI/180.)*mydelta))-(PI/180.)*   
00169                   ((180.-mydelta)/2.);
00170            }
00171            makeflat(width, delem, chi);
00172            if (rcurv < 0.) {
00173               X[0]=(-fabs(rcurv))*cos(gamma+(k*(PI/180.)*mydelta))-A[0];
00174               X[1]=0.;
00175               X[2]=fabs(rcurv)*sin(gamma+(k*(PI/180.)*mydelta))-A[2];
00176            }
00177            if (rcurv > 0.) {
00178               X[0]=fabs(rcurv)*cos(gamma+theta-(k*(PI/180.)*mydelta))-A[0];
00179               X[1]=0.;
00180               X[2]=(-fabs(rcurv))*sin(gamma+theta-(k*(PI/180.)*mydelta))-A[2];
00181            }
00182 
00183            for (i=0; i < 4; i++)  {
00184               for (j=0; j < 3; j++) {
00185                   baseblind[i][j][k] = baseflat[i][j]+X[j];
00186               } 
00187            }  
00188        }
00189     }
00190 
00191     /* FLAT BLINDS CALCULATION */
00192 
00193     else {
00194 
00195        nsurf=1;
00196        makeflat(width,depth,angle*(PI/180.));
00197        for (i=0; i < 4; i++) {
00198            for (j=0; j < 3; j++) {
00199               baseblind[i][j][0] = baseflat[i][j];
00200            }
00201        }
00202     }
00203 
00204     printhead(argc, argv);
00205 
00206 
00207     /* REPEAT THE BASIC CURVED OR FLAT SLAT TO GET THE OVERALL BLIND */
00208 
00209     for (l = 1; l <= nslats; l++)
00210        printslat(l);
00211     exit(0);
00212 userr:
00213     fprintf(stderr,
00214            "Usage: %s mat name depth width height nslats angle [-r|+r rcurv]\n",
00215            argv[0]);
00216     exit(1);
00217 }
00218 
00219 
00220