Calculate the Distance From The Center
of the Earth to the Center of the Tunnel

#! /usr/bin/python3
# ===================================================================
# Given an great circle angle from the center of a sphere
# (the earth) and the radius of the sphere (the earth),
# calculate the distance from the center of the sphere
# (the center of the earth) to the center of the tunnel.
# ===================================================================

from math import pi, radians, cos, sin, asin, sqrt

# -------------------------------------------------------------------
# calculate the tunnel distance
#   rad  radius of sphere (the earth)
#   ang  great circle angle
# -------------------------------------------------------------------

def great_circle_tunnel_distance(radius,angle):

    # ---- convert degrees to radians

    angrad = radians(angle/2.0)

    return radius * cos(angrad)


# -------------------------------------------------------------------
# ---- main
# -------------------------------------------------------------------

if '__main__' == __name__:

    # ---- radius of earth

    radm = 3956.0              # miles
    radk = 6371.0              # kilometers

    # ---- great circle angle

    gca = 45.0                 # degrees

    d = great_circle_tunnel_distance(radm,gca)

    print()
    print('distance from the center of the earth')
    print('to the center of the tunnel')
    print()
    print(f'radius  : {radm} miles')
    print(f'gs angle: {gca} degrees')
    print()
    print(f'distance to tunnel: {d} miles')