Solution (source code)

= Solution

<Archimedes' principle> states that the resultant <hydrostatic pressure> <force> on a body equals the weight of the <fluid> displaced, directed opposite to gravity. Let $V_d$ be the displaced <fluid> region, with outward normal $\widehat{\mathbf n}$ from the body into the <fluid>. Since the <fluid> <pressure> <force> is inward,
$$
\mathbf F_b=-\oint_{\partial V_d}p\widehat{\mathbf n}\,dA
=-\int_{V_d}\nabla p\,dV.
$$
Hydrostatic balance is $\nabla p=\rho_f\mathbf g$, with downward <gravitational acceleration> $\mathbf g$. Therefore
$$
\boxed{\mathbf F_b=-\int_{V_d}\rho_f\mathbf g\,dV
=-\rho_fV_d\mathbf g}
$$
for uniform <fluid> density and gravity. Uniform atmospheric <pressure> gives no net <force> on a closed surface. For a floating body, the same displaced-volume construction includes the free surface; any significant air <buoyancy> can be included as a second displaced <fluid>.

A freely floating body of <mass> $m$ satisfies $mg=\rho_f gV_d$, so its displaced <volume (thermodynamics)> is $m/\rho_f$. A homogeneous body of density $\rho_b<\rho_f$ floats with submerged fraction $\rho_b/\rho_f$; if $\rho_b>\rho_f$, hydrostatic <buoyancy> alone cannot support it. The <buoyant force> acts through the <centre of buoyancy>, the <centroid> of the displaced <volume (thermodynamics)> for constant density, while weight acts through the <centre of mass>. Their relative positions determine rotational equilibrium and stability. For a fully submerged body, a <centre of mass> below the <centre of buoyancy> gives a restoring <torque>; a floating body's changing displaced shape additionally requires the <metacentric height> criterion. <Surface tension>, externally driven flow and contact <forces> can alter the simple <force> balance.