
# TourSlerps.py
# Andrew Davison, ad@coe.psu.ac.th, August 2025
'''
  Draw a series of Great Circles between cities 
  in the tour list on an Orthographic map.
  See TourSquad.py for a curve made with Squad.
'''
import math

import cartopy.crs as ccrs
import cartopy.feature as cf
import matplotlib.pyplot as plt

import nav
from Quat import Quat



def plotCity(ax, city, lat, lon):
  # Add marker
  ax.plot(lon, lat, 'o', color='green', 
         transform=ccrs.PlateCarree())
  # label city
  ax.text(lon, lat, " "+city, color='green', 
         transform=ccrs.PlateCarree())



tour = [ 'London', 'Paris', 'Madrid', 'Rome', 
         'Bern', 'Warsaw', 'Amsterdam', 'London']

cities = nav.loadCityData()
cityCoords = [ (nav.readCoord(cities, city)) 
                                  for city in tour]

slerps = []
quats = [ Quat.fromLatLon(*coord) for coord in cityCoords]
for i in range(len(quats) - 1):
  slerps += Quat.slerpsNInv(quats[i], quats[i+1], 10)
iCoords = [ q.toLatLon() for q in slerps]

plt.figure()
ax = plt.axes(projection=ccrs.Orthographic())

lineSep = 5
ax.gridlines(draw_labels=True, ls='--',
             xlocs=range(-180, 181, lineSep),
             ylocs=range(-90, 91, lineSep))
ax.coastlines()
ax.add_feature(cf.BORDERS, ls=':')


lats, lons = zip(*iCoords)
plt.plot(lons, lats, color='blue', linestyle='--',
         transform=ccrs.PlateCarree())
                # straight lines link the coords

for i, city in enumerate(tour):
  plotCity(ax, city, *cityCoords[i])

plt.title(f"Slerps Cities Tour\n")
plt.show()
