package main import ( "math" "strconv" "strings" ) func haversine(lat1, lon1, lat2, lon2 float64) float64 { const R = 6371 // Earth radius in km dLat := (lat2 - lat1) * math.Pi / 180 dLon := (lon2 - lon1) * math.Pi / 180 a := math.Sin(dLat/2)*math.Sin(dLat/2) + math.Cos(lat1*math.Pi/180)*math.Cos(lat2*math.Pi/180)*math.Sin(dLon/2)*math.Sin(dLon/2) c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a)) return R * c } func angleDifference(a, b float64) float64 { diff := math.Mod(math.Abs(a-b), 360) if diff > 180 { diff = 360 - diff } return diff } func bearing(lat1, lon1, lat2, lon2 float64) float64 { lat1Rad := lat1 * math.Pi / 180 lat2Rad := lat2 * math.Pi / 180 dLon := (lon2 - lon1) * math.Pi / 180 y := math.Sin(dLon) * math.Cos(lat2Rad) x := math.Cos(lat1Rad)*math.Sin(lat2Rad) - math.Sin(lat1Rad)*math.Cos(lat2Rad)*math.Cos(dLon) brng := math.Atan2(y, x) * 180 / math.Pi if brng < 0 { brng += 360 } return brng } func parseTime(s string) float64 { parts := strings.Split(s, ":") if len(parts) != 3 { return 0 } h, _ := strconv.Atoi(parts[0]) m, _ := strconv.Atoi(parts[1]) sec, _ := strconv.Atoi(parts[2]) return float64(h*3600 + m*60 + sec) }