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.
Vimal Chawda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.