| 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/4.0; |
| 30 |
double d = 1.0; |
| 31 |
double h = sqrt(2.0 * d*d * (1.0 - sin(theta))); |
| 32 |
double y, z; |
| 33 |
|
| 34 |
cout << "picture capillary; capillary := nullpicture;\n"; |
| 35 |
cout << "addto capillary contour " << mpoint(0.0,h); |
| 36 |
|
| 37 |
for(int i=99;i>2;i--) { |
| 38 |
z = (i/100.0) * h; |
| 39 |
y = capillary(z,h,d); |
| 40 |
cout << " .. " << mpoint(y,z); |
| 41 |
} |
| 42 |
|
| 43 |
cout << " -- " << mpoint(y,-0.5); |
| 44 |
cout << " -- " << mpoint(0.0,-0.5); |
| 45 |
cout << " -- cycle;\n"; |
| 46 |
} |