I think you are making this too hard.
The diameter of the top surface of the media in a conical tank or hopper is a function of the heght and the cone angle.
Perhaps a sketch will illustrate the point.
This first tank has a 45
o conical bottom.
As the media height in the tank increases, so does the diameter used to calculate the media volume. At a depth of 1 inch, the diameter is 2 inches. At a depth of 4", the diameter is 8"
Now this hopper has a 30
o cone.
This changes the height to diameter relationship. Now for a media detph of 1" the diameter is 1.15 inches and for a media depth of 4 inches the diameter is 4.62 inches.
The radius to height relationship in these two examples can be defined as:
Radius = TAN(T) * height
Where T is the angle of the hopper cone.
By using this as our diameter/height to relationship we can eliminate the necessity of entering a diameter which will be chaning with height anyways.
So algebraically rearranging our equation and expressing all values in terms of height and the angle of the tank cone, we get
Volume = (Tan(T)*height)
2 * height * PI/3
Volume = height
3 * tan(T)
2 * PI/3
PI/3 is 1.0472. Tan(T) will be fixed (unless you are chaning out the tank all of the time). Let K be a constant that you program according to the tank cone angle such that
K = tan(T)
2 * PI/3.
Then the volume calculation becomse very simple. It is K * Height
3
Go one step farther, make K = (tan(T)
2 * PI/3)/231 to convert to gallons in a single step.
Lets say you have a tank with a 60
0 bottom.
Then your calculation becomes CPT VOLUME_IN_GALLONS "Height**3 * .01359997"