ntheta = 400
nearly = 1.0 # - 1e-5

xmax = 1.5

R0 = np.sqrt(beta)/(1 + np.sqrt(beta))
shell = equation6.Shell(beta=beta)
theta = np.linspace(0.0, nearly*shell.th_infty, ntheta)
R, th1 = shell.radius(theta, method='brent', full=True)
alph = alpha(R, theta)
R_approx = crw_misc_utils.radius(theta, crw_misc_utils.th1_approx(theta, beta))
m = R_approx > 0.0

th_tail = conic_parameters.theta_tail(beta, xi=None,
                                      f=conic_parameters.finf_CRW)
print('th1_infty =', np.degrees(shell.th1_infty), np.degrees(th1[-4:]))
print('alpha_infty =', np.degrees(alph[-4:]))

# Gradient: d phi_1 / d phi
grad = np.diff(shell.th1_infty - th1) / np.diff(shell.th_infty - theta)
# Theoretical estimate:
grad0 = beta*(np.pi / (shell.th1_infty
                       - np.sin(shell.th1_infty)*np.cos(shell.th1_infty)) - 1)
print('gradient:', grad0, grad[-4:])

b_a = np.tan(th_tail)
x_tail = np.linspace(-xmax, xmax, 3)
y_tail = -b_a*(x_tail - 1.0)

        # Geberalized CRW solution
        R_crw = R_from_theta(theta, beta, xi)
        x_crw = R_crw*np.cos(theta)
        y_crw = R_crw*np.sin(theta)

        # Matched conic parameters
        A = conic_parameters.A(beta, xi)
        th_conic = np.degrees(conic_parameters.theta_c(beta, xi))
        c = Conic(A=A, th_conic=th_conic)
        t = c.make_t_array()
        x_con = c.x(t)
        y_con = c.y(t)

        # Hyperbola fit to tail
        th_tail = np.degrees(conic_parameters.theta_tail(beta, xi))

        # First draw the asymptote
        D = (1 + np.sqrt(beta))/np.sqrt(beta)
        b_a = np.tan(np.radians(th_tail))
        x_cone = np.linspace(-10*D, 10*D, 3)
        y_cone = -b_a*(x_cone - 0.5*(1 + np.sqrt(beta))*D)
        print(th_tail, b_a, x_cone, y_cone)


        # c2 = Conic(A=0.3*A, th_conic=-th_tail)
        # t2 = c2.make_t_array()
        # x_tail = c2.x(t2)
        # y_tail = c2.y(t2)

        # # Renormalize to give the same B