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