Need help for a coding challenge

I got stuck on a coding challenge that is called Tank Trunk.
The challenge wants from me to calculate the remaining volume of the liquid of the Tank Truck.
But I tried to find the formula of the remaining volume of the liquid of the Tank Truck.
Could you help me find that formula ?

The link to the challenge:

Not really a coding problem, but a math problem.

So let’s go through it real quick:
You got the height of the liquid h, the diameter of the tank d and the total volume of the tank.
The tank is a cylinder which is a special kind of prism which has a volume of profile * height. The still liquid in the tank is the same, hence we only need the percentage the liquid is filling in the circle to calculate the actual volume.
Meaning we need “green area” divided by “circle area”.

What do we see in the pictue? We have a triangle and the liquid below.
The liquid PLUS the triangle are a segment of the circle. So we need it’s area and then subtract the triangle. The sides of the triangle are the diameter, the height is the diameter minus h. Because the triangle can be divided into two rectangular triangles, we can use the sinus to calculate the missing angles. With those we can calculate both the area of the triangles, as well as of the circle-segment. Their difference is the green area. And that divided by the area of the circle and then multiplied by the total volume is the actual volume.

These formulas contain all the information needed to solve it:

1 Like

And here I am, trying to construct it from memory - damn you wikipedia xD

At least your solution works without internet connection…