"""Lecture 7, the steady climb angle against the thrust-to-weight ratio for several lift-to-drag ratios, from the
engine's flight.performance.climb_angle (sin(gamma) = T/W - cos(gamma)/E), with the trainer example of the note
and the HAL Kiran of the questions. Writes img/fig-07-climb-angle.png."""
import numpy as np
from _visual import plt, save, despine, MAROON, BLUE, GREEN, AMBER, INK
from flight.performance import climb_angle

TW = np.linspace(0.0, 0.6, 121)
ES = [(8, AMBER), (12, GREEN), (16, BLUE), (40, MAROON)]
POINTS = [("trainer of the example", 0.25, 16), ("HAL Kiran", 0.379, 12.7)]

if __name__ == "__main__":
    fig, ax = plt.subplots(figsize=(10, 5.2))
    for E, c in ES:
        ax.plot(TW, [np.degrees(climb_angle(t, E)) for t in TW], color=c, lw=2.2, label=f"$E$ = {E}")
    for lab, tw, E in POINTS:
        g = np.degrees(climb_angle(tw, E))
        ax.plot(tw, g, "o", color=INK, ms=7)
        ax.annotate(f"{lab}: {g:.1f}°", (tw, g), xytext=(10, -16), textcoords="offset points", fontsize=11)
    ax.axhline(0, color="#8a8378", lw=0.8)
    ax.set_xlabel("thrust-to-weight ratio $T/W$")
    ax.set_ylabel("steady climb angle $\\gamma$ (deg)")
    ax.set_xlim(0, 0.6)
    ax.legend(fontsize=11, frameon=False, loc="upper left")
    despine(ax)
    save(fig, "fig-07-climb-angle")
