1 |
greg |
2.1 |
#ifndef lint |
2 |
schorsch |
2.5 |
static const char RCSid[] = "$Id: gencat.c,v 2.4 2003/06/08 12:03:09 schorsch 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 |
schorsch |
2.5 |
int |
81 |
greg |
2.1 |
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: gencat material name x0 y0 z0 x1 y1 z1 k d\n"); |
95 |
|
|
exit(1); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
cmtype = argv[1]; |
99 |
|
|
cname = argv[2]; |
100 |
|
|
x0 = atof(argv[3]); y0 = atof(argv[4]); z0 = atof(argv[5]); |
101 |
|
|
x1 = atof(argv[6]); y1 = atof(argv[7]); z1 = atof(argv[8]); |
102 |
|
|
k = atof(argv[9]); d = atof(argv[10]); |
103 |
|
|
D = sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0)); |
104 |
|
|
b = Newton(0.0); |
105 |
|
|
z = z0 - k * cosh(b); |
106 |
|
|
printhead(argc, argv); |
107 |
|
|
|
108 |
|
|
n = 0; |
109 |
|
|
for (h=0; h<=D; ) { |
110 |
|
|
f = k * cosh(k*h+b) + z; |
111 |
|
|
fprim = k* k * sinh(k*h+b); |
112 |
|
|
delh = d / sqrt(1+fprim*fprim); |
113 |
|
|
fprim = k * k * sinh(k*(h+delh/2)+b); |
114 |
|
|
hb = sqrt(.01*fprim*fprim/(1+fprim*fprim)); |
115 |
|
|
fb = sqrt(.01/(1+(fprim*fprim))); |
116 |
|
|
hc = sqrt(.04/(1+fprim*fprim)); |
117 |
|
|
fc = sqrt(.04*fprim*fprim/(1+fprim*fprim)); |
118 |
|
|
|
119 |
|
|
printf("\n%s polygon %s.%d\n", cmtype, cname, ++n); |
120 |
|
|
printf("0\n0\n9\n"); |
121 |
|
|
printf("%f %f %f\n", h*(x1-x0)/D+x0, h*(y1-y0)/D+y0, f); |
122 |
|
|
if (fprim < 0) |
123 |
|
|
{ |
124 |
|
|
printf("%f %f %f\n", (h+hc)*(x1-x0)/D+x0, (h+hc)*(y1-y0)/D+y0, f-fc); |
125 |
|
|
printf("%f %f %f\n", (h+hb)*(x1-x0)/D+x0, (h+hb)*(y1-y0)/D+y0, f+fb); |
126 |
|
|
} |
127 |
|
|
else if (fprim > 0) |
128 |
|
|
{ |
129 |
|
|
printf("%f %f %f\n", (h+hc)*(x1-x0)/D+x0, (h+hc)*(y1-y0)/D+y0, f+fc); |
130 |
|
|
printf("%f %f %f\n", (h-hb)*(x1-x0)/D+x0, (h-hb)*(y1-y0)/D+y0, f+fb); |
131 |
|
|
} |
132 |
|
|
else |
133 |
|
|
{ |
134 |
|
|
printf("%f %f %f\n", (h+.2)*(x1-x0)/D+x0, (h+.2)*(y1-y0)/D+y0, f); |
135 |
|
|
printf("%f %f %f\n", h*(x1-x0)/D+x0, h*(y1-y0)/D+y0, f+.1); |
136 |
|
|
} |
137 |
|
|
h += delh; |
138 |
|
|
} |
139 |
schorsch |
2.5 |
return 0; |
140 |
greg |
2.1 |
} |
141 |
|
|
|