| 1 | greg | 2.1 | #ifndef lint | 
| 2 | schorsch | 2.4 | static const char       RCSid[] = "$Id: gencat.c,v 2.3 2003/02/22 02:07:23 greg Exp $"; | 
| 3 | greg | 2.1 | #endif | 
| 4 |  |  | /***************************************************************************** | 
| 5 |  |  | This program is to make series of right triangles forming hyperbolic cosin | 
| 6 |  |  | (ie, cosh) curve in between of 2 points. | 
| 7 |  |  | ^ | 
| 8 |  |  | f(h)| | 
| 9 |  |  | | | 
| 10 |  |  | |               0\ pc:(hc, fc) | 
| 11 |  |  | |               |    \ | 
| 12 |  |  | |               |       \ | 
| 13 |  |  | |               |          \ | 
| 14 |  |  | |   pa:(ha, fa) 0-------------0 pb:(hb, fb) | 
| 15 |  |  | | | 
| 16 |  |  | 0------------------------------------------------> h | 
| 17 |  |  |  | 
| 18 |  |  | Given arguments: | 
| 19 |  |  | material | 
| 20 |  |  | name | 
| 21 |  |  | (x0, y0, z0), (x1, y1, z1) | 
| 22 |  |  | k        const. value K | 
| 23 |  |  | d        distant length desired between 2 points | 
| 24 |  |  |  | 
| 25 |  |  | ******************************************************************************/ | 
| 26 |  |  |  | 
| 27 |  |  | #include <stdio.h> | 
| 28 | greg | 2.3 | #include <stdlib.h> | 
| 29 | greg | 2.1 | #include <math.h> | 
| 30 | greg | 2.2 |  | 
| 31 | greg | 2.1 | char  *cmtype, *cname; | 
| 32 |  |  | double z0, z1; | 
| 33 |  |  | double k, D; | 
| 34 |  |  | double d; | 
| 35 |  |  | double z, h; | 
| 36 |  |  |  | 
| 37 |  |  | #ifdef notdef | 
| 38 |  |  | double Newton( b) | 
| 39 |  |  | double b; | 
| 40 |  |  | { | 
| 41 |  |  | if (fabs(cosh(k*D+b)-cosh(b)-(z1-z0)/k) < .001) | 
| 42 |  |  | return (b); | 
| 43 |  |  | else { | 
| 44 |  |  | b = b - (cosh(k*D+b)-cosh(b)-(z1-z0)/k)/(sinh(k*D+b)-sinh(b)); | 
| 45 |  |  | Newton (b); | 
| 46 |  |  | } | 
| 47 |  |  | } | 
| 48 |  |  | #endif | 
| 49 |  |  |  | 
| 50 |  |  | double Newton(bl) | 
| 51 |  |  | double bl; | 
| 52 |  |  | { | 
| 53 |  |  | double b; | 
| 54 |  |  | int n = 10000; | 
| 55 |  |  |  | 
| 56 |  |  | while (n--) { | 
| 57 |  |  | b = bl- (cosh(k*D+bl)-cosh(bl)-(z1-z0)/k)/(sinh(k*D+bl)-sinh(bl)); | 
| 58 |  |  | if (fabs(b-bl) < .00001) | 
| 59 |  |  | return(b); | 
| 60 |  |  | bl = b; | 
| 61 |  |  | } | 
| 62 |  |  | fprintf(stderr, "Interation limit exceeded -- invalid K value\n"); | 
| 63 |  |  | exit(1); | 
| 64 |  |  | } | 
| 65 |  |  |  | 
| 66 |  |  |  | 
| 67 | schorsch | 2.4 | static void | 
| 68 |  |  | printhead(ac, av)               /* print command header */ | 
| 69 |  |  | register int  ac; | 
| 70 |  |  | register char  **av; | 
| 71 |  |  | { | 
| 72 |  |  | putchar('#'); | 
| 73 |  |  | while (ac--) { | 
| 74 |  |  | putchar(' '); | 
| 75 |  |  | fputs(*av++, stdout); | 
| 76 |  |  | } | 
| 77 |  |  | putchar('\n'); | 
| 78 |  |  | } | 
| 79 |  |  |  | 
| 80 | greg | 2.1 | main (argc, argv) | 
| 81 |  |  | int argc; | 
| 82 |  |  | char *argv[]; | 
| 83 |  |  | { | 
| 84 |  |  | double x0, y0; | 
| 85 |  |  | double x1, y1; | 
| 86 |  |  | double b; | 
| 87 |  |  | double delh; | 
| 88 |  |  | double f, fprim; | 
| 89 |  |  | double hb, hc, fb, fc; | 
| 90 |  |  | int  n; | 
| 91 |  |  |  | 
| 92 |  |  | if (argc != 11) { | 
| 93 |  |  | fprintf(stderr, "Usage: gencat material name x0 y0 z0 x1 y1 z1 k d\n"); | 
| 94 |  |  | exit(1); | 
| 95 |  |  | } | 
| 96 |  |  |  | 
| 97 |  |  | cmtype = argv[1]; | 
| 98 |  |  | cname = argv[2]; | 
| 99 |  |  | x0 = atof(argv[3]); y0 = atof(argv[4]); z0 = atof(argv[5]); | 
| 100 |  |  | x1 = atof(argv[6]); y1 = atof(argv[7]); z1 = atof(argv[8]); | 
| 101 |  |  | k = atof(argv[9]); d = atof(argv[10]); | 
| 102 |  |  | D = sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0)); | 
| 103 |  |  | b = Newton(0.0); | 
| 104 |  |  | z = z0 - k * cosh(b); | 
| 105 |  |  | printhead(argc, argv); | 
| 106 |  |  |  | 
| 107 |  |  | n = 0; | 
| 108 |  |  | for (h=0; h<=D; ) { | 
| 109 |  |  | f =  k * cosh(k*h+b) + z; | 
| 110 |  |  | fprim = k* k * sinh(k*h+b); | 
| 111 |  |  | delh = d / sqrt(1+fprim*fprim); | 
| 112 |  |  | fprim = k * k * sinh(k*(h+delh/2)+b); | 
| 113 |  |  | hb = sqrt(.01*fprim*fprim/(1+fprim*fprim)); | 
| 114 |  |  | fb = sqrt(.01/(1+(fprim*fprim))); | 
| 115 |  |  | hc = sqrt(.04/(1+fprim*fprim)); | 
| 116 |  |  | fc = sqrt(.04*fprim*fprim/(1+fprim*fprim)); | 
| 117 |  |  |  | 
| 118 |  |  | printf("\n%s polygon %s.%d\n", cmtype, cname, ++n); | 
| 119 |  |  | printf("0\n0\n9\n"); | 
| 120 |  |  | printf("%f %f %f\n", h*(x1-x0)/D+x0, h*(y1-y0)/D+y0, f); | 
| 121 |  |  | if (fprim < 0) | 
| 122 |  |  | { | 
| 123 |  |  | printf("%f %f %f\n", (h+hc)*(x1-x0)/D+x0, (h+hc)*(y1-y0)/D+y0, f-fc); | 
| 124 |  |  | printf("%f %f %f\n", (h+hb)*(x1-x0)/D+x0, (h+hb)*(y1-y0)/D+y0, f+fb); | 
| 125 |  |  | } | 
| 126 |  |  | else if (fprim > 0) | 
| 127 |  |  | { | 
| 128 |  |  | printf("%f %f %f\n", (h+hc)*(x1-x0)/D+x0, (h+hc)*(y1-y0)/D+y0, f+fc); | 
| 129 |  |  | printf("%f %f %f\n", (h-hb)*(x1-x0)/D+x0, (h-hb)*(y1-y0)/D+y0, f+fb); | 
| 130 |  |  | } | 
| 131 |  |  | else | 
| 132 |  |  | { | 
| 133 |  |  | printf("%f %f %f\n", (h+.2)*(x1-x0)/D+x0, (h+.2)*(y1-y0)/D+y0, f); | 
| 134 |  |  | printf("%f %f %f\n", h*(x1-x0)/D+x0, h*(y1-y0)/D+y0, f+.1); | 
| 135 |  |  | } | 
| 136 |  |  | h += delh; | 
| 137 |  |  | } | 
| 138 |  |  | } | 
| 139 |  |  |  |