"""Lecture 39: yawing and rolling moment coefficients against sideslip, controls centred, from the derivatives that
Nelson (1998), Appendix B, tabulates for the NAVION and for the Boeing 747 at Mach 0.25. Straight-line model.
Writes img/fig-39-slopes.png."""
import numpy as np
from _visual import plt, save, despine, MAROON, BLUE, INK
import _stab as S

BETA = np.linspace(-10, 10, 50)

if __name__ == "__main__":
    fig, (a, b) = plt.subplots(1, 2, figsize=(10, 4.0))
    fig.subplots_adjust(wspace=0.32)
    for d, c, lab in ((S.NAVION, BLUE, "NAVION"), (S.B747, MAROON, "747, Mach 0.25")):
        a.plot(BETA, d["cn_beta"] * np.radians(BETA), color=c, lw=2.6, label=lab)
        b.plot(BETA, d["cl_beta"] * np.radians(BETA), color=c, lw=2.6, label=lab)
    a.set_ylabel("yawing moment $C_n$"); b.set_ylabel("rolling moment $C_l$")
    a.set_title(r"rising: $C_{n_\beta}>0$, stable in yaw", fontsize=12); b.set_title(r"falling: $C_{l_\beta}<0$, stable in roll", fontsize=12)
    for ax in (a, b):
        ax.axhline(0, color=INK, lw=0.8); ax.axvline(0, color=INK, lw=0.8); ax.set_xlabel("sideslip β (°)"); despine(ax)
    a.legend(frameon=False, fontsize=11)
    save(fig, "fig-39-slopes")
