/* D:\j_Iam_TEMP\_jh\jh_k123_Rectangle_v6.wxmx */

/* Rectangle  */

kill(all);

ro:1000;g:9.81;H:3;B:1;

P:integrate(ro*g*(H-h)*B,h,0,H);

mP:integrate(ro*g*((H-h)**2)*B,h,0,H);

h_D:mP/P;

/* Variant 2 (from down coordinates) */

mP_down:integrate((ro*g*(H-h)*B)*h,h,0,H);

h_D_down:mP_down/P;

/* Rectangle with h1 */

h1:1;

P_h1:integrate(ro*g*(H-h+h1)*B,h,0,H);

mP_h1:integrate(ro*g*((H-h+h1)**2)*B,h,0,H);

h_D_h1:mP_h1/P_h1;

/* Rectangle with h1 (down) */

mP_h1_down:integrate(ro*g*((H-h+h1)*h)*B,h,0,H);

h_D_h1_down:mP_h1_down/P_h1;

/* test rectangle + h1 */

h_D_h1+h_D_h1_down;

/*  Rectangle with h1 (up) + p_m */

p_m:10000;

P_h1_pm:integrate(ro*g*(H-h+h1+p_m/(ro*g))*B,h,0,H);

mP_h1_pm_up:integrate(ro*g*(H-h+h1+p_m/(ro*g))*(H-h)*B,h,0,H);

h_D_h1_pm_up:mP_h1_pm_up/P_h1_pm;

/*  Rectangle with h1 (down) + p_m */

P_h1_pm:integrate(ro*g*(H-h+h1+p_m/(ro*g))*B,h,0,H);

mP_h1_pm_down:integrate(ro*g*(H-h+h1+p_m/(ro*g))*h*B,h,0,H);

h_D_h1_pm_down:mP_h1_pm_down/P_h1_pm;

/* test all H = 4  OK! */
h_D_h1_pm_up+h_D_h1_pm_down;

/* -----------Triangle------------- */

H:4;

fB(h):=(B/H)*(H-h);

fB(0);fB(H);

P_tri:integrate(ro*g*(H-h)*fB(h),h,0,H);

mP_tri:integrate(ro*g*((H-h)**2)*fB(h),h,0,H);

h_D_tri:mP_tri/P_tri;

/* Trapetion */

P_trap:integrate(ro*g*(H-h)*fB(h),h,0,H/2);

mP_trap:integrate(ro*g*((H-h)**2)*fB(h),h,0,H/2);

h_D_trap:mP_trap/P_trap;

mP_trap_down:integrate(ro*g*((H-h)*h)*fB(h),h,0,H/2);

h_D_trap_down:mP_trap_down/P_trap;

/* Circle UP half */

R:1;

fB_circle(h):=2*sqrt(R**2-h**2);

fB_circle(0);fB_circle(R);

P_cir_up:integrate(ro*g*(R-h)*fB_circle(h),h,0,R);

P_cir_up,numer;

mP_cir_up:integrate(ro*g*((R-h)**2)*fB_circle(h),h,0,R);

h_D_cir_up:mP_cir_up/P_cir_up,numer;

/* Test of  Circle UP half */

h_c:(1-0.4244)*R;p:ro*g*h_c;w:(%pi*(R**2))/2;P:p*w,numer;I:0.1098*R**4;

h_D:h_c+I/(h_c*w),numer;

/* Circle DOWN half  */

fB_circle_d(h):=2*sqrt(R**2-(R-h)**2);

fB_circle_d(0);fB_circle_d(R);

P_cir_d:integrate(ro*g*(R-h)*fB_circle_d(h),h,0,R);

mP_cir_d:integrate(ro*g*((R-h)*h)*fB_circle_d(h),h,0,R);

h_D_cir_d:mP_cir_d/P_cir_d,numer;

/* Test of Circle DOWN half  */

h_c:(0.4244)*R;p:ro*g*h_c;w:(%pi*(R**2))/2;P:p*w,numer;I:0.1098*R**4;

h_D:h_c+I/(h_c*w),numer; 

/* test from down coordinates */
R-h_D;