| 1 |
#ifndef lint
|
| 2 |
static const char RCSid[] = "$Id: gencat.c,v 2.5 2003/11/16 10:29:38 schorsch Exp $";
|
| 3 |
#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 |
#include <stdlib.h>
|
| 29 |
#include <math.h>
|
| 30 |
|
| 31 |
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 |
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 |
int
|
| 81 |
main (argc, argv)
|
| 82 |
int argc;
|
| 83 |
char *argv[];
|
| 84 |
{
|
| 85 |
double x0, y0;
|
| 86 |
double x1, y1;
|
| 87 |
double b;
|
| 88 |
double delh;
|
| 89 |
double f, fprim;
|
| 90 |
double hb, hc, fb, fc;
|
| 91 |
int n;
|
| 92 |
|
| 93 |
if (argc != 11) {
|
| 94 |
fprintf(stderr, "Usage: %s material name x0 y0 z0 x1 y1 z1 k d\n",
|
| 95 |
argv[0]);
|
| 96 |
exit(1);
|
| 97 |
}
|
| 98 |
|
| 99 |
cmtype = argv[1];
|
| 100 |
cname = argv[2];
|
| 101 |
x0 = atof(argv[3]); y0 = atof(argv[4]); z0 = atof(argv[5]);
|
| 102 |
x1 = atof(argv[6]); y1 = atof(argv[7]); z1 = atof(argv[8]);
|
| 103 |
k = atof(argv[9]); d = atof(argv[10]);
|
| 104 |
D = sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0));
|
| 105 |
b = Newton(0.0);
|
| 106 |
z = z0 - k * cosh(b);
|
| 107 |
printhead(argc, argv);
|
| 108 |
|
| 109 |
n = 0;
|
| 110 |
for (h=0; h<=D; ) {
|
| 111 |
f = k * cosh(k*h+b) + z;
|
| 112 |
fprim = k* k * sinh(k*h+b);
|
| 113 |
delh = d / sqrt(1+fprim*fprim);
|
| 114 |
fprim = k * k * sinh(k*(h+delh/2)+b);
|
| 115 |
hb = sqrt(.01*fprim*fprim/(1+fprim*fprim));
|
| 116 |
fb = sqrt(.01/(1+(fprim*fprim)));
|
| 117 |
hc = sqrt(.04/(1+fprim*fprim));
|
| 118 |
fc = sqrt(.04*fprim*fprim/(1+fprim*fprim));
|
| 119 |
|
| 120 |
printf("\n%s polygon %s.%d\n", cmtype, cname, ++n);
|
| 121 |
printf("0\n0\n9\n");
|
| 122 |
printf("%f %f %f\n", h*(x1-x0)/D+x0, h*(y1-y0)/D+y0, f);
|
| 123 |
if (fprim < 0)
|
| 124 |
{
|
| 125 |
printf("%f %f %f\n", (h+hc)*(x1-x0)/D+x0, (h+hc)*(y1-y0)/D+y0, f-fc);
|
| 126 |
printf("%f %f %f\n", (h+hb)*(x1-x0)/D+x0, (h+hb)*(y1-y0)/D+y0, f+fb);
|
| 127 |
}
|
| 128 |
else if (fprim > 0)
|
| 129 |
{
|
| 130 |
printf("%f %f %f\n", (h+hc)*(x1-x0)/D+x0, (h+hc)*(y1-y0)/D+y0, f+fc);
|
| 131 |
printf("%f %f %f\n", (h-hb)*(x1-x0)/D+x0, (h-hb)*(y1-y0)/D+y0, f+fb);
|
| 132 |
}
|
| 133 |
else
|
| 134 |
{
|
| 135 |
printf("%f %f %f\n", (h+.2)*(x1-x0)/D+x0, (h+.2)*(y1-y0)/D+y0, f);
|
| 136 |
printf("%f %f %f\n", h*(x1-x0)/D+x0, h*(y1-y0)/D+y0, f+.1);
|
| 137 |
}
|
| 138 |
h += delh;
|
| 139 |
}
|
| 140 |
return 0;
|
| 141 |
}
|
| 142 |
|