--- ray/src/gen/genblinds.c 1992/08/27 13:51:59 2.3 +++ ray/src/gen/genblinds.c 2003/11/16 10:29:38 2.11 @@ -1,9 +1,6 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: genblinds.c,v 2.11 2003/11/16 10:29:38 schorsch Exp $"; #endif - /* * genblind2.c - make some curved or flat venetian blinds. * @@ -19,15 +16,13 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include +#include #include +#include -#ifndef atof -extern double atof(); -#endif +#define PI 3.14159265358979323846 +#define DELTA 10. /* MINIMAL SUSTAINED ANGLE IN DEGREES */ -#define PI 3.141592653589793 -#define DELTA 5. /* MINIMAL SUSTAINED ANGLE IN DEGREES */ - double baseflat[4][3], baseblind[4][3][180]; double A[3],X[3]; char *material, *name; @@ -35,128 +30,18 @@ double height; int nslats, nsurf; -main(argc, argv) -int argc; -char *argv[]; -{ - double fabs(); - double width, delem, depth, rcurv = 0.0, angle; - double beta, gamma, theta, chi; - int i, j, k, l; +static void makeflat(double w, double d, double a); +static void printslat(int n); +static void printhead(register int ac, register char **av); - if (argc != 8 && argc != 10) - goto userr; - material = argv[1]; - name = argv[2]; - depth = atof(argv[3]); - width = atof(argv[4]); - height = atof(argv[5]); - nslats = atoi(argv[6]); - angle = atof(argv[7]); - if (argc == 10) - if (!strcmp(argv[8], "-r")) - rcurv = atof(argv[9]); - else if (!strcmp(argv[8], "+r")) - rcurv = -atof(argv[9]); - else - goto userr; - -/* CURVED BLIND CALCULATION */ - - if (rcurv != 0) { - - /* BLINDS SUSTAINED ANGLE */ - - theta = 2*asin(depth/(2*fabs(rcurv))); - - /* HOW MANY ELEMENTARY SURFACES SHOULD BE CALCULATED ? */ - - nsurf = (theta / ((PI/180.)*DELTA)); - - /* WHAT IS THE DEPTH OF THE ELEMENTARY SURFACES ? */ - - delem = 2*fabs(rcurv)*sin((PI/180.)*(DELTA/2.)); - - beta = (PI-theta)/2.; - gamma = beta -((PI/180.)*angle); - - - - if (rcurv < 0) { - A[0]=fabs(rcurv)*cos(gamma); - A[0] *= -1; - A[1]=0.; - A[2]=fabs(rcurv)*sin(gamma); - } - if (rcurv > 0) { - A[0]=fabs(rcurv)*cos(gamma+theta); - A[1]=0.; - A[2]=fabs(rcurv)*sin(gamma+theta); - A[2] *= -1; - } - - for (k=0; k < nsurf; k++) { - if (rcurv < 0) { - chi=(PI/180.)*((180.-DELTA)/2.) - (gamma+(k*(PI/180.)*DELTA)); - } - if (rcurv > 0) { - chi=(PI-(gamma+theta)+(k*(PI/180.)*DELTA))-(PI/180.)* - ((180.-DELTA)/2.); - } - makeflat(width, delem, chi); - if (rcurv < 0.) { - X[0]=(-fabs(rcurv))*cos(gamma+(k*(PI/180.)*DELTA))-A[0]; - X[1]=0.; - X[2]=fabs(rcurv)*sin(gamma+(k*(PI/180.)*DELTA))-A[2]; - } - if (rcurv > 0.) { - X[0]=fabs(rcurv)*cos(gamma+theta-(k*(PI/180.)*DELTA))-A[0]; - X[1]=0.; - X[2]=(-fabs(rcurv))*sin(gamma+theta-(k*(PI/180.)*DELTA))-A[2]; - } - - for (i=0; i < 4; i++) { - for (j=0; j < 3; j++) { - baseblind[i][j][k] = baseflat[i][j]+X[j]; - } - } - } - } - - /* FLAT BLINDS CALCULATION */ - - if (rcurv == 0.) { - - nsurf=1; - makeflat(width,depth,angle*(PI/180.)); - for (i=0; i < 4; i++) { - for (j=0; j < 3; j++) { - baseblind[i][j][0] = baseflat[i][j]; - } - } - } - - printhead(argc, argv); - - -/* REPEAT THE BASIC CURVED OR FLAT SLAT TO GET THE OVERALL BLIND */ - - for (l = 1; l <= nslats; l++) - printslat(l); - exit(0); -userr: - fprintf(stderr, - "Usage: %s mat name depth width height nslats angle [-r|+r rcurv]\n", - argv[0]); - exit(1); -} - - -makeflat(w,d,a) -double w, d, a; +void +makeflat( + double w, + double d, + double a +) { - double sin(), cos(); double h; h = d*sin(a); @@ -177,8 +62,10 @@ double w, d, a; } -printslat(n) /* print slat # n */ -int n; +void +printslat( /* print slat # n */ + int n +) { register int i, k; @@ -194,9 +81,11 @@ int n; } -printhead(ac, av) /* print command header */ -register int ac; -register char **av; +void +printhead( /* print command header */ + register int ac, + register char **av +) { putchar('#'); while (ac--) { @@ -205,3 +94,125 @@ register char **av; } putchar('\n'); } + + +int +main( + int argc, + char *argv[] +) +{ + double width, delem, depth, rcurv = 0.0, angle; + double beta, gamma, theta, chi = 0; + int i, j, k, l; + + + if (argc != 8 && argc != 10) + goto userr; + material = argv[1]; + name = argv[2]; + depth = atof(argv[3]); + width = atof(argv[4]); + height = atof(argv[5]); + nslats = atoi(argv[6]); + angle = atof(argv[7]); + if (argc == 10) + if (!strcmp(argv[8], "-r")) + rcurv = atof(argv[9]); + else if (!strcmp(argv[8], "+r")) + rcurv = -atof(argv[9]); + else + goto userr; + + /* CURVED BLIND CALCULATION */ + + if (rcurv != 0) { + + /* BLINDS SUSTAINED ANGLE */ + + theta = 2*asin(depth/(2*fabs(rcurv))); + + /* HOW MANY ELEMENTARY SURFACES SHOULD BE CALCULATED ? */ + + nsurf = (int)(theta / ((PI/180.)*DELTA)) + 1; + + /* WHAT IS THE DEPTH OF THE ELEMENTARY SURFACES ? */ + + delem = 2*fabs(rcurv)*sin((PI/180.)*(DELTA/2.)); + + beta = (PI-theta)/2.; + gamma = beta -((PI/180.)*angle); + + + + if (rcurv < 0) { + A[0]=fabs(rcurv)*cos(gamma); + A[0] *= -1; + A[1]=0.; + A[2]=fabs(rcurv)*sin(gamma); + } + if (rcurv > 0) { + A[0]=fabs(rcurv)*cos(gamma+theta); + A[1]=0.; + A[2]=fabs(rcurv)*sin(gamma+theta); + A[2] *= -1; + } + + for (k=0; k < nsurf; k++) { + if (rcurv < 0) { + chi=(PI/180.)*((180.-DELTA)/2.) - (gamma+(k*(PI/180.)*DELTA)); + } + if (rcurv > 0) { + chi=(PI-(gamma+theta)+(k*(PI/180.)*DELTA))-(PI/180.)* + ((180.-DELTA)/2.); + } + makeflat(width, delem, chi); + if (rcurv < 0.) { + X[0]=(-fabs(rcurv))*cos(gamma+(k*(PI/180.)*DELTA))-A[0]; + X[1]=0.; + X[2]=fabs(rcurv)*sin(gamma+(k*(PI/180.)*DELTA))-A[2]; + } + if (rcurv > 0.) { + X[0]=fabs(rcurv)*cos(gamma+theta-(k*(PI/180.)*DELTA))-A[0]; + X[1]=0.; + X[2]=(-fabs(rcurv))*sin(gamma+theta-(k*(PI/180.)*DELTA))-A[2]; + } + + for (i=0; i < 4; i++) { + for (j=0; j < 3; j++) { + baseblind[i][j][k] = baseflat[i][j]+X[j]; + } + } + } + } + + /* FLAT BLINDS CALCULATION */ + + if (rcurv == 0.) { + + nsurf=1; + makeflat(width,depth,angle*(PI/180.)); + for (i=0; i < 4; i++) { + for (j=0; j < 3; j++) { + baseblind[i][j][0] = baseflat[i][j]; + } + } + } + + printhead(argc, argv); + + + /* REPEAT THE BASIC CURVED OR FLAT SLAT TO GET THE OVERALL BLIND */ + + for (l = 1; l <= nslats; l++) + printslat(l); + exit(0); +userr: + fprintf(stderr, + "Usage: %s mat name depth width height nslats angle [-r|+r rcurv]\n", + argv[0]); + exit(1); +} + + +