Google earth bearing computation

I have problem near to great circle and I have one rocket trajectory data.
I would like to find Visibility area on earth so I used horizon distance and plot the data but the algorithm fails near the poles. Please find the image belowenter image description here

It should follow straight but it started curve. Below is the whole code and error part is

# Calculate the distance to the horizon for each point
def distance_to_horizon(altitude_km):
    EARTH_RADIUS_KM = 6371
    return np.sqrt(2 * EARTH_RADIUS_KM * altitude_km + altitude_km**2)

Here is the all the code below. Can you please guide me what should we do in this case?

import pandas as pd
import numpy as np
import simplekml
from geopy.distance import geodesic

# Define the path to the new Excel file and KML output path
new_file_path = 'C:\Users\vimalkumar.chawda\Desktop\LOS\new_data.xlsx'
kml_file_path = 'C:\Users\vimalkumar.chawda\Desktop\LOS\trajectory_with_horizon_points.kml'  # Output path

# Read the data from the new Excel file
data = pd.read_excel(new_file_path, header=None)

# Manually set column names
data.columns = ['Lat', 'Lon', 'Alt', 'Time']

# Ensure that latitudes, longitudes, altitudes, and time are numeric
data['Lat'] = pd.to_numeric(data['Lat'], errors='coerce')
data['Lon'] = pd.to_numeric(data['Lon'], errors='coerce')
data['Alt'] = pd.to_numeric(data['Alt'], errors='coerce')
data['Time'] = pd.to_numeric(data['Time'], errors='coerce')

# Drop rows with NaN values in Lat, Lon, Alt, or Time
data_cleaned = data.dropna(subset=['Lat', 'Lon', 'Alt', 'Time']).copy()

# Calculate the distance to the horizon for each point
def distance_to_horizon(altitude_km):
    EARTH_RADIUS_KM = 6371
    return np.sqrt(2 * EARTH_RADIUS_KM * altitude_km + altitude_km**2)

# Apply the calculation safely
data_cleaned['Horizon_Distance_KM'] = data_cleaned['Alt'].apply(distance_to_horizon)

# Initialize KML
kml = simplekml.Kml()

# Function to determine color based on index
def get_color(index):
    colors = [simplekml.Color.red, simplekml.Color.green, simplekml.Color.blue, simplekml.Color.yellow]
    return colors[index % len(colors)]

# Add trajectory points with alternating colors
current_orbit = 0
previous_time = data_cleaned.iloc[0]['Time']

for i, row in data_cleaned.iterrows():
    lat = row['Lat']
    lon = row['Lon']
    horizon_dist = row['Horizon_Distance_KM']
    current_time = row['Time']
    
    # Determine if a new orbit has started (e.g., time reset or large time gap)
    if current_time < previous_time or (current_time - previous_time) > 6000:  # Arbitrary large time gap to indicate new orbit
        current_orbit += 1
    previous_time = current_time

    # Add the trajectory point to KML
    traj_point = kml.newpoint(name=f'Trajectory Point ({lat}, {lon})', coords=[(lon, lat)])
    traj_point.style.iconstyle.color = get_color(current_orbit)
    traj_point.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png'

    # Calculate the points to the east and west at the horizon distance
    point = (lat, lon)
    
    # Check for poles and clamp latitude values if necessary
    if abs(lat) > 89.0:
        horizon_point_east = point
        horizon_point_west = point
    else:
        east_point = geodesic(kilometers=horizon_dist).destination(point, 90)  # East
        west_point = geodesic(kilometers=horizon_dist).destination(point, 270)  # West
    
        # Clamp latitude values
        east_lat = max(min(east_point.latitude, 89.0), -89.0)
        west_lat = max(min(west_point.latitude, 89.0), -89.0)
    
        horizon_point_east = (east_lat, east_point.longitude)
        horizon_point_west = (west_lat, west_point.longitude)
    
    # Add the horizon points to KML
    horizon_point_east_kml = kml.newpoint(name=f'Horizon Point East ({horizon_point_east[0]}, {horizon_point_east[1]})', coords=[(horizon_point_east[1], horizon_point_east[0])])
    horizon_point_east_kml.style.iconstyle.color = get_color(current_orbit)
    horizon_point_east_kml.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png'
    
    horizon_point_west_kml = kml.newpoint(name=f'Horizon Point West ({horizon_point_west[0]}, {horizon_point_west[1]})', coords=[(horizon_point_west[1], horizon_point_west[0])])
    horizon_point_west_kml.style.iconstyle.color = get_color(current_orbit)
    horizon_point_west_kml.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png'

# Save KML file
kml.save(kml_file_path)
print(f"KML file has been saved to {kml_file_path}")

I am expecting that plot will be straight line or window line of both side of the trajectory which will be visibility area.

New contributor

Vimal Chawda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật