Horizontal tank with hemispherical ends depth to capacity calculation I am trying to find an accurate way of calculating the capacity of an underground tank at a given depth.  The tank manufacturer has provided a strapping table for the tank which tells me the capacity at various depths.
Gauge Depth (cm)  /  Capacity (Liters)
2cm = 29.8 liters
12cm = 240.4 liters
...
66cm = 2372.8 liters
118cm = 4008.4 liters

However, I would like to find an equation for calculating the volume of liquid in the tank based on the liquid depth level.
They have provided the following dimensions for the tank:
1219mm Diameter
3785mm Long
3978 Liters Capacity

The tank is horizontal with hemispherical ends.  It is safe to assume that the radius of the hemispherical ends is 1/2 of the diameter of the tank.
Any help or direction would be greatly appreciated!
 A: You can divide the tank into a sphere (formed from the two  hemispherical ends) and a cylinder.  Wikipedia Spherical cap gives the volume as $\frac{\pi h^2}{3}(3r-h)$ where $r$ is the radius of the sphere and $h$ the depth.  Then Circular Segment gives the area of the segment as $\frac{r^2}{2}(\theta - \sin \theta )$ where $\theta=\arccos(\frac{r-h}{r})$.  Multiply this last by the length, add the spherical cap, and there you are.
A: There are three parts to the tank: the two hemispherical ends and the middle cylinder. The two hemispherical ends add up to one whole sphere, so we'll just consider a sphere and a cylinder. Just to check the data you've given: at 1219mm diameter, the sphere has volume roughly 948.44 liters. The cylinder has diameter 1219mm and height (3785-1219)=2566mm. The volume is roughly then 2994.7 liters. So I'm guessing that there's either a typo on your data sheet (either the total tank capacity is closer 3948 liters, or the total length of the tank is closer to 3815mm), or a mis-description: the ends are not capped by exact hemispheres. 
Never mind that, since we are on a mathematics site and who cares about plugging in real numbers /end_sarcasm 
Assume your tank is composed of two hemispherical ends of radius $R$, and a central cylinder of radius $R$ and length $L$. The diameter would be $2R$ and total length $L + 2R$. We want to calculate volume as a function of water depth. 
Since your tank is lying horizontally, the height of water, which we will call $h$, should be the same inside the cyclinder portion and inside the spherical portions. So we will compute the total volume as a sum of the volume inside the sphere (remember: two hemispheres make one whole sphere) and the volume inside the cylinder.
$$ V_{tot} = V_s + V_c $$
If you know calculus, you can compute the volume of the spherical cap of height $h$ by evaluating an integral. But the formula is well-known:
$$ V_s = \frac{\pi h^2}{3}(3R - h) $$
For the cylinder, the volume at height $h$ is equal to the length $L$ multiplied by the area of the circular segment of height $h$:
$$ V_c = L \times A = L \times \left[ R^2 \cos^{-1}\left(\frac{R-h}{R}\right) - (R - h) \sqrt{2Rh - h^2}\right] $$
with the formula for $A$ derivable by elementary geometry/trigonometry, or again through the evaluation of an integral. So putting it all together you have that 
$$ V_{tot} = \frac{\pi h^2}{3}(3R - h) + L \times \left[ R^2 \cos^{-1}\left(\frac{R-h}{R}\right) - (R - h) \sqrt{2Rh - h^2}\right] $$
which gives 
2 cm  => 11.4 L
5 cm  => 46.4 L
10 cm => 134.6 L 
20 cm => 388.9 L 
30 cm => 716.7 L 
40 cm => 1094.5 L 
50 cm => 1504.5 L 
60 cm => 1930.8 L 
61 cm (just a tiny bit over half full) => 1971.6 L

A: Let $R$ be the radius of the tank and let the end-to-end length be $L + 2R$.  At each depth $x$ above the center of the tank (where $-R \le x \le R$), the tank's cross-section is a rectangle of length $L$ and width $2r(x)$, plus semicircular caps of radius $r(x)$.  The radius satisfies $r(x)^2 + x^2 = R^2$.  So the volume at depth $d$ is
$$
\begin{eqnarray}
V(d) &=& \int_{-R}^{-R+d} V'(x) dx \\
&=& \int_{-R}^{-R+d} \left(2 L r(x) + \pi r(x)^2\right) dx \\
&=& \int_{-R}^{-R+d} \left(2 L \sqrt{R^2 - x^2} + \pi R^2 - \pi x^2\right) dx \\
&=& 2 L R^2 \tan^{-1}\left(\sqrt{\frac{d}{2R-d}}\right) + L(d-R)\sqrt{d(2R-d)} + \pi\left(Rd^2 - \frac{1}{3}d^3\right).
\end{eqnarray}
$$
This fits your numbers reasonably well for $R=609.5\text{mm}$ and $L=2566.0\text{mm}$; it could be improved by knowing the thickness of the tank walls and whether the shape deviates from a perfect cylinder plus hemispherical caps (e.g., is it flattened at the bottom)?
A: One thing is clear: you can't get 4008.4 litres into a tank with a capacity of 3978 litres. So you are right not to trust the manufacturer's dipstick.
A: There is an excel template to calculate horizontal cylindrical tank, with hemispherical both ends, and usually called capsule tank. Excel formulas can calculate liquid volume in partially filled horizontal capsule tank.
http://maruzar.blogspot.com/2011/12/horizontal-hemispherical-cylindrical.html
A: I would like to share the mathematical steps I took to solve this problem.  I solved for a horizontal tank without the hemispherical caps.  So essentially the problem is, "How does the cross-sectional area of a circle change with respect to height from the bottom of the tank?"  
I know that the length of the tank does not change, therefore I only need to solve for the change in area of the circle in contact with the fluid and then multiply by the tank's length to get the fluid's volume.  I can first solve the problem for a Unit Circle and then scale by $R^2$ for any tank, where $R$ is the tank's radius.

The equation for a unit circle is  $$x^2+y^2=1$$ where $R^2=1$
We will be integrating over the change in $y$ (change in fluid height), therefore we need $x$ in terms of $y$
\begin{align}
x^2+y^2 &=1 \\
x^2 &= 1-y^2\\
x &=\pm \sqrt{1-y^2} \ \text{length of chord will be} =2 \times |x|
\end{align}
therefore the length of the chord is: $l_{\text{chord}}=2(1-y^2)^{1/2}$
The area of the circle in contact with the fluid is
$$A=\int_{-1}^h 2(1-y^2)^{1/2} \ dy$$
The volume of fluid in the tank is
$$V=\int_{-1}^h 2(1-y^2)^{1/2} \ dy \times L$$
Integrating:
$$V=L \int_{-1}^h 2(1-y^2)^{1/2} \ dy $$
*$(1-y^2)$ is a trig identity form of $a^2-y^2$; $a=1$
set $y=a\sin(\theta)$ or $y=a\sin(u)$, $\frac{dy}{du}=a\cos(u) \Rightarrow dy=a\cos(u) \ du$
\begin{align}
&=L \int_{\frac{-\pi}{2}}^{h'}2(1-\sin^2(u))^{1/2}\cos(u) \ du \\
\nonumber\\
&=L \int_{\frac{-\pi}{2}}^{h'}2(\cos^2(u))^{1/2} \cos(u) \ du
\end{align}
*where $\sin^2(\theta)+\cos^2(\theta)=1$, therefore: $1-\sin^2(\theta)=\cos^2(\theta)$
\begin{align}
&=L \int_{\frac{-\pi}{2}}^{h'}2\cos(u)\cos(u) \ du \\
\nonumber\\
&=L \int_{\frac{-\pi}{2}}^{h'}2\cos^2(u) \ du 
\end{align}
*A double angle identity for $\cos(2u)=2\cos^2(u)-1$, therefore: $2\cos^2(u)=1+\cos(2u)$
$$=L \int_{\frac{-\pi}{2}}^{h'}(1+\underbrace{\cos(2u)}) \ du$$
looking at the underbraced portion:
set $(2u)=s$, therefore: $\frac{ds}{du}=2$
$$ds=2 \ du \Rightarrow du=\frac{1}{2} \ ds$$
therefore the underbraced portion can be written as:
\begin{align}
\int \cos(2u) \ du &=\int \cos(s) \times \frac{1}{2} \ ds \\
&=\frac{1}{2} \int \cos(s) \ ds \\
&=\frac{1}{2} \sin(s)+c \ \ \text{back-sub the substitution}\\
&=\frac{1}{2} \sin(2u)+c
\end{align}
we can now do our integration by parts:
$$=L \int 1 \ du + L \int \cos(2u) \ du$$
$$L(u+c)\Biggr|_{\frac{\pi}{2}}^{h'}+L\left[\frac{1}{2}\sin(2u)+c\right]_{\frac{\pi}{2}}^{h'}$$
*the $c$'s are the constants of integration and will cancel out when the integral is evaluated.
$$=L\left[u+\frac{1}{2}\sin(2u)\right]_{\frac{\pi}{2}}^{h'}$$
*A double angle identity for $\sin(2u)$:
\begin{align}
\sin(2u) &=2\sin(u)\cos(u)\\
&=2\sin(u)(1-\sin^2(u))^{\frac{1}{2}}
\end{align}
therefore
$$=L\left[u+\frac{1}{2} \times 2\sin(u)(1-\sin^2(u))^{\frac{1}{2}}\right]_{\frac{\pi}{2}}^{h'}$$
*Recall $y=\sin(u) \Rightarrow u=\arcsin(y)$
\begin{align}
&=L\left[\arcsin(y)+y \times (1-y^2)^{\frac{1}{2}}\right]_{-1}^{h} \\
\\
&=L\left[\left(\arcsin(h)+h \times (1-h^2)^{\frac{1}{2}}\right)-\left(\arcsin(-1)+(-1)(1-(-1)^2)^{\frac{1}{2}}\right)\right] \\
\\
&=L\left[\frac{\pi}{2}+\left(\arcsin(h)+h(1-h^2)^{\frac{1}{2}}\right)\right]
\end{align}
*For any tank with radius $R$
$$V=R^2 \times L\left[\frac{\pi}{2}+\left(\arcsin(h)+h\sqrt{(1-h^2)}\right)\right]$$
Interestingly, I ran into this problem while out on a frac job and we had missplaced our dipstick to our acid transport.  We needed to keep tabs on how much acid we were pumping into the well.
