You are trying to fit a sphere into a 5-sided box, but sometimes it does not fit completely. Write a function to calculate how much of the sphere is outside (above the rim of) the box.
There are 3 possible situations:
- The sphere fits completely in the box. The answer will be 0.
- The sphere sits on the rim of the box. The answer will be more than half of the total volume.
- The sphere sits on the bottom of the box.
You can see each situation here:
You must write a program or function to compute this value to at least 4 significant digits.
Input: 4 non-negative real numbers in whatever format is convenient* - width, length, depth of the box (interior measurements), and diameter of the sphere.
Output: 1 non-negative real number in a usable format* - the total volume (not the percentage) of the sphere outside the box.
* must be convertible to/from a decimal string
You are encouraged to limit your use of trigonometry as much as possible.
This is a popularity contest, so think outside the box!