"""Lecture 13, the axial-force (drag) coefficient of slender bodies against Mach number: the dataset's V-2 (power off
and on), representative short-range ballistic missile and BrahMos-class missile. All these tables are ESTIMATES in
the dataset (data/vehicles/*.toml), drawn here for their common shape: flat at low speed, a peak just above Mach 1,
a slow fall after. Writes img/fig-13-bodies.png."""
import numpy as np
from _visual import plt, save, despine, MAROON, BLUE, GREEN, AMBER, INK, GREY
from flight import vehicle

M = np.linspace(0, 5, 300)
BODIES = [("V-2 (estimated), power off", "v2", False, MAROON, "-"), ("V-2 (estimated), motor burning", "v2", True, MAROON, "--"),
          ("short-range ballistic missile (representative)", "srbm-representative", False, BLUE, "-"),
          ("BrahMos class (representative)", "brahmos-representative", False, GREEN, "-")]


def ca(name, on, m):
    a = vehicle.load(name).aero
    return a.ca_on(m) if on else a.ca(m)


if __name__ == "__main__":
    fig, ax = plt.subplots(figsize=(10, 5.4))
    for lab, nm, on, c, ls in BODIES:
        ax.plot(M, [ca(nm, on, m) for m in M], color=c, lw=2.4, ls=ls, label=lab)
    ax.axvspan(0.8, 1.2, color="#f3e3c3", zorder=0)
    ax.set_xlim(0, 5); ax.set_ylim(0, 0.8)
    ax.set_xlabel("Mach number"); ax.set_ylabel("axial-force coefficient $C_A$")
    ax.legend(frameon=False, fontsize=11, loc="upper right")
    despine(ax)
    save(fig, "fig-13-bodies")
