import math _EARTH_RADIUS_KM = 6371.0088 def haversine_km(lat1: float, lon1: float, lat2: float, lon2: float) -> float: p1, p2 = math.radians(lat1), math.radians(lat2) dp, dl = p2 - p1, math.radians(lon2 - lon1) a = math.sin(dp / 2) ** 2 + math.cos(p1) * math.cos(p2) * math.sin(dl / 2) ** 2 return 2 * _EARTH_RADIUS_KM * math.asin(math.sqrt(a)) def destination(lat: float, lon: float, bearing_deg: float, km: float) -> tuple[float, float]: """출발점에서 방위각 방향으로 km 떨어진 지점.""" d = km / _EARTH_RADIUS_KM p1, l1, b = math.radians(lat), math.radians(lon), math.radians(bearing_deg) p2 = math.asin(math.sin(p1) * math.cos(d) + math.cos(p1) * math.sin(d) * math.cos(b)) l2 = l1 + math.atan2(math.sin(b) * math.sin(d) * math.cos(p1), math.cos(d) - math.sin(p1) * math.sin(p2)) return math.degrees(p2), (math.degrees(l2) + 540) % 360 - 180