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