>>5337812Calculate the area of the liquid on A using the appropriate math formula, then on B if you cross a horizontal line it will create a triangle up to a certain point, calculate that triangle area using the formula for that, if that area is larger than the liquid's area you'll know that the line should be lower so all you need to do is use that layer and make it = to the liquid area.
If that area is still smaller then you'll to add the area that is on top of that triangle, if you cross another line on the top side it will form another triangle at the very top and a parallelogram so triangle + parallelogram should be equal to the liquid area.
something like this, i haven't done math in decades