Debian Codegraph @

texmf-dist/doc/latex/metaplot/examples/capillary.cc

raw
1 /* Simple capillary surface */
2
3 #include<sstream>
4 #include<iostream>
5 #include<cmath>
6
7 using namespace std;
8
9 string mpoint(double x, double y) {
10 ostringstream pointstring;
11 pointstring.setf(ios_base::fixed,ios_base::floatfield);
12 pointstring.precision(5);
13 pointstring << '(' << x << ',' << y << ')';
14 return pointstring.str();
15 }
16
17 double arccosh(double x) {
18 return log(x + sqrt(x*x-1));
19 }
20
21 double capillary(double z, double h, double d) {
22 return arccosh(2.0*d/z) - arccosh(2.0*d/h)
23 + sqrt(4.0 - h*h/(d*d)) - sqrt(4.0 - z*z/(d*d));
24 }
25
26 const double pi = 3.1415926535897932384626433832795;
27
28 int main() {
29 double theta = pi/6.0;
30 double d = 1.0;
31 double h = sqrt(2.0 * d*d * (1.0 - sin(theta)));
32 double y, z;
33
34 double zmax = h; double zmin = -0.5;
35 double ymax = capillary(0.03*h,h,d);
36
37 cout << "picture capillary.fplot; capillary.fplot := nullpicture;\n";
38 cout << "addto capillary.fplot contour " << mpoint(0.0,1.0);
39 for(int i=99;i>2;i--) {
40 z = (i/100.0) * h;
41 y = capillary(z,h,d);
42 cout << " .. " << mpoint(y/ymax,(z-zmin)/(zmax-zmin));
43 }
44 cout << " -- " << mpoint(1.0,0.0);
45 cout << " -- " << mpoint(0.0,0.0);
46 cout << " -- cycle;\n\n";
47
48 cout << "picture capillary.lplot; capillary.lplot := nullpicture;\n";
49 cout << "addto capillary.lplot doublepath " << mpoint(0.0,1.0);
50 for(int i=99;i>2;i--) {
51 z = (i/100.0) * h;
52 y = capillary(z,h,d);
53 cout << " .. " << mpoint(y/ymax,(z-zmin)/(zmax-zmin));
54 }
55 cout << ";\n\n";
56
57 cout.setf(ios_base::fixed,ios_base::floatfield);
58 cout.precision(5);
59 cout << "numeric capillary.xleft; ";
60 cout << "capillary.xleft = 0.0;\n";
61 cout << "numeric capillary.xright; ";
62 cout << "capillary.xright = " << ymax << ";\n";
63 cout << "numeric capillary.ybot; ";
64 cout << "capillary.ybot = " << zmin << ";\n";
65 cout << "numeric capillary.ytop; ";
66 cout << "capillary.ytop = " << zmax << ";\n\n";
67
68 cout << "pair capillary.contactpoint; ";
69 cout << "capillary.contactpoint = (0.0, 1.0);\n";
70 cout << "numeric capillary.contactangle; ";
71 cout << "capillary.contactangle = " << theta * 180/pi << ";\n";
72 }