Conical Tank geometry with Python

Hi All,
@c.poupin

In order to find the top radius R2 of my Tank according to its total volume VT and the choosen angle theta, I should iterate the value of bottom radius R1 which start from 3.40m (see the image bellow)

To find a solution to R2 (Top radius) I used the volume formula of conical geometry which give me two solutions after computing the discriminant and I should choose the positive one
image

according to my calculations in Excel If I fixe choosen angle = 45 degrees the approximate solution which I can take is:
angle = 45.056
bottom radius R1 = 4.17m
Top radius R2 = 10.158m

But python give me this:
image

So, what is missing in my script bellow, and can I find the exact value for the angle 45 degrees?

import sys
import clr
import math
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#Total volume (volume water + volume chimeny)
VT = 1023.7797
#
H_water = 6
# initial bottom radius 
Bottom_radius = 3.4
# desired angle
angle_Tank = 45

Axis = Vector.ByCoordinates(0, 0, 1)
Center = Point.ByCoordinates(0, 0, 0)
#initial bottom radius value in iteration
temp_radius = Line.ByStartPointEndPoint(Center, Point.ByCoordinates(Bottom_radius , 0, 0))
length_radius = temp_radius.Length

#compute the discriminant of 2nd degree equation
delta = length_radius**2 + 4 * (3 * VT/ (math.pi * H_water) -(length_radius**2))
OUT = delta
# first Top radius solution
R1 = (-length_radius - math.sqrt(delta))/2
# 2nd Top radius solution
R2 = (-length_radius + math.sqrt(delta))/2
# choosing the positive solution for Top radius
if R1 > 0:
    Top_radius = R1
else:
    Top_radius = R2
out = []    
k = 0
# iterate bottom radius to compute disired Top radius and angle
offset_radius = 0.01
while k < 100:
    k +=1
    length_radius = length_radius + offset_radius
    delta = length_radius**2 + 4 * (3 * VT/ (math.pi * H_water) -(length_radius**2))
    R1 = (-length_radius - math.sqrt(delta))/2
    R2 = (-length_radius + math.sqrt(delta))/2
    if R1 > 0:
        Top_radius = R1
        temp_angle = math.degrees(math.atan(H_water / (Top_radius - length_radius)))
        if math.ceil(temp_angle) == angle_Tank:
            out.append(length_radius)
            out.append(Top_radius)
            out.append(temp_angle)   
            break
    else:
        Top_radius = R2
        temp_angle = math.degrees(math.atan(H_water / (Top_radius - length_radius)))
        if math.ceil(temp_angle) == angle_Tank:
            out.append(length_radius)
            out.append(Top_radius)
            out.append(temp_angle)   
            break
OUT = out

Thanks.

Hi All,
I’ve solve my issue by increasing rounding of offset_radius to 0.001 and in the same time increasing k to 764.
Also, I’ve correct the error I made for the condition which give the angle

if math.ceil(temp_angle) == angle_Tank:

replaced by :

if math.ceil(temp_angle) > angle_Tank:

which give me this:
image

Thanks.