import math

earth_km = 6371.0
light_km_s = 299792.458
fiber_index = 1.468

def compare(distance_km, altitude_km):
    radius = earth_km + altitude_km
    angle = distance_km / earth_km
    visibility_angle = 2.0 * math.acos(earth_km / radius)
    max_angle = min(math.radians(10.0), 0.99 * visibility_angle)
    hops = max(1, math.ceil(angle / max_angle))
    step = angle / hops
    clearance = radius * math.cos(step / 2.0) - earth_km
    assert clearance > 0.0
    orbital_distance = hops * 2.0 * radius * math.sin(step / 2.0)
    space_distance = 2.0 * altitude_km + orbital_distance
    space_ms = 1000.0 * space_distance / light_km_s
    fiber_ms = 1000.0 * distance_km * fiber_index / light_km_s
    assert orbital_distance <= radius * angle + 1e-9
    return hops, space_ms, fiber_ms

for altitude in [550.0, 1150.0]:
    denominator = fiber_index - (earth_km + altitude) / earth_km
    crossover = 2.0 * altitude / denominator
    print(f"altitude={altitude:.0f}km arc_crossover={crossover:.1f}km")
    for distance in [1000.0, 3000.0, 6000.0]:
        hops, space, fiber = compare(distance, altitude)
        print(f"  ground={distance:.0f}km hops={hops} "
              f"space={space:.3f}ms fiber={fiber:.3f}ms")
print("Earth-clearance and chord-length checks: passed")
