#P6988. Gasoline Volume Calculation in Tilted Tank Car
Gasoline Volume Calculation in Tilted Tank Car
Gasoline Volume Calculation in Tilted Tank Car
A tank car transporting gasoline has the shape of a cylinder with two spherical caps at its ends. The cylinder has a diameter \(d\) and a length \(l\), and each spherical cap is part of a sphere with radius \(r\) (with \(2r \ge d\)). Due to a rail accident the tank has derailed and now lies on the ground with a tilt. The tilt is measured as the height difference \(t\) between the bottom points of the cylinder at its left and right sides. The gasoline level is measured by the vertical distance \(h\) from the bottom point of the cylinder (on the left side) to the top surface of the gasoline. It is guaranteed that the top surface always intersects the cylindrical part, i.e. \(0 \le h \le t + d\sqrt{1-(t/l)^2}\).
Your task is to compute the volume of gasoline remaining in the tank. The overall tank consists of three parts:
- Cylinder: for \(x\) from 0 to \(l\) the cross‐section is a circle with radius \(d/2\).
- Left spherical cap: for \(x\) in [\(- (r - a)\), 0] where \(a=\sqrt{r^2-(d/2)^2}\), the cross‐section is a circle with radius \(R(x)=\sqrt{r^2-(x+a)^2}\).
- Right spherical cap: for \(x\) in [\(l, l+(r-a)\)] with the same \(a\), the cross‐section is a circle with radius \(R(x)=\sqrt{r^2-(x-(l+a))^2}\).
In the tank's own coordinate system the horizontal axis \(x\) runs along the length of the tank. The vertical coordinate in each cross‐section is denoted by \(y\); the cylinder cross–section (or circle) has its bottom at \(y=0\) and top at \(y=d\). The tank is tilted so that the bottom of the tank varies linearly as \(B(x)=\frac{t}{l}\,x\). Therefore, a point with coordinates \((x,y)\) in the tank has an actual vertical elevation of \(y+B(x)\). The gasoline surface is horizontal and located at an absolute height \(h\) (measured from the left bottom point of the cylinder, where \(B(0)=0\)).
Thus, for a given \(x\), the gasoline fills the cross–section (a circle) from its bottom up to the horizontal line at \(y = L(x)\) where \[ L(x)=h - \frac{t}{l}x. \] After shifting the circle (whose center is at \(y=d/2\)) by \(d/2\) we set \(H = L(x)-d/2\). Let \(R\) be the radius of the circle at that slice. The filled area in the slice is computed as follows:
- If \(H \ge R\), the whole circle is filled, so area = \(\pi R^2\).
- If \(H \le -R\), none of the circle is filled, so area = 0.
- Otherwise, the filled area is given by the area of a circular segment: \[ A = R^2 \arccos\Bigl(\frac{-H}{R}\Bigr) + H \sqrt{R^2 - H^2}. \]
The total gasoline volume is obtained by integrating the filled area along \(x\) over the entire tank (left cap, cylinder, right cap). Since a closed-form solution is non–trivial, a numerical integration (for example, using the trapezoidal rule with sufficient subdivisions) will work.
inputFormat
The input consists of five space–separated floating point numbers:
- \(d\): diameter of the cylinder.
- \(l\): length of the cylindrical part.
- \(r\): radius of the sphere from which the spherical caps are taken (\(2r \ge d\)).
- \(t\): measured tilt of the tank (vertical difference between the two bottom points of the cylinder, \(0 \le t \le l\)).
- \(h\): measured height from the bottom of the cylinder (at the left side) to the gasoline surface (\(0 \le h \le t+d\sqrt{1-(t/l)^2}\)).
outputFormat
Output a single floating point number representing the volume of gasoline remaining in the tank. Print the answer with 6 decimal places.
sample
4 10 3 0 2
119.380566