summaryrefslogtreecommitdiff
path: root/graphics/metaplot/examples/cap1.cc
blob: 1be25f56731d083e1fe4b48dc98467c0fb4b5964 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Simple capillary surface */  
  
#include<sstream>
#include<iostream>
#include<cmath>

using namespace std;

string mpoint(double x, double y) {
  ostringstream pointstring;
  pointstring.setf(ios_base::fixed,ios_base::floatfield);
  pointstring.precision(5);
  pointstring << '(' << x << ',' << y << ')';  
  return pointstring.str();
}

double arccosh(double x) {
  return log(x + sqrt(x*x-1));
}

double capillary(double z, double h, double d) {
  return arccosh(2.0*d/z) - arccosh(2.0*d/h)
         + sqrt(4.0 - h*h/(d*d)) - sqrt(4.0 - z*z/(d*d));
}

const double pi = 3.1415926535897932384626433832795;

int main() {
  double theta = pi/4.0;
  double d = 1.0;
  double h = sqrt(2.0 * d*d * (1.0 - sin(theta)));
  double y, z;
  
  cout << "picture capillary; capillary := nullpicture;\n";
  cout << "addto capillary contour " << mpoint(0.0,h);
  
  for(int i=99;i>2;i--) {
    z = (i/100.0) * h;
    y = capillary(z,h,d);
    cout << " .. " << mpoint(y,z);
  }
  
  cout << " -- " << mpoint(y,-0.5);
  cout << " -- " << mpoint(0.0,-0.5);  
  cout << " -- cycle;\n";
}