double ForceBalance(double r, double h, double ps, double pf)
{
const double PI=3.14159265359;
const double G= 9.80665;
double v_ball = 4.0/3.0 * PI * r*r*r;
double v_seg = PI*(r*h*h - h*h*h/3);
double f = G * (v_ball * (ps-pf) + v_seg*pf);
return f;
}
#ifdef TEST
#include <iostream>
using namespace std;
int main()
{
double r = 1.0;
double h = 0.397;
double ps = 920.0;
double pf = 1025.0;
cout << "The total force applied to the ice ball with radius " << r
<< "m with cape " << h << "m above the water is" << endl;
double force = ForceBalance(r, h, ps, pf);
cout << abs(force) << "N and directed " << (force>0 ? "down" : "up") << endl;
return 0;
}
#endif
Comments