"""Lecture 6, the reductions as a tree: switch terms off in the general equations to get each vehicle's model.
Writes img/fig-06-tree.png."""
from _visual import plt, save, INK, MAROON, BLUE, GREEN, AMBER, PURPLE, GREY

BOX = dict(boxstyle="round,pad=0.45", fc="#f1ece0", ec=GREY, lw=1)
NODES = {"gen": (0.5, 0.92, "the general equations\nrotating, flattened Earth"),
         "sph": (0.27, 0.62, "non-rotating sphere\n($\\omega_E=0$)"),
         "flat": (0.76, 0.62, "flat Earth\n(all small ratios dropped)"),
         "lv": (0.07, 0.27, "launch\nvehicle"),
         "entry": (0.26, 0.27, "entry\ncapsule"),
         "two": (0.45, 0.27, "free flight:\ntwo-body"),
         "air": (0.7, 0.27, "aircraft\n(Lecture 7)"),
         "mis": (0.92, 0.27, "tactical\nmissile")}
EDGES = [("gen", "sph", "drop rotation"), ("gen", "flat", "drop rotation,\ncurvature, $J_2$"), ("sph", "lv", ""),
         ("sph", "entry", "$T=0$"), ("sph", "two", "$T=L=D=0$"), ("flat", "air", ""), ("flat", "mis", "")]

if __name__ == "__main__":
    fig, ax = plt.subplots(figsize=(10.5, 5.6))
    for a, b, lab in EDGES:
        xa, ya, _ = NODES[a]
        xb, yb, _ = NODES[b]
        ax.annotate("", xy=(xb, yb + 0.08), xytext=(xa, ya - 0.08), arrowprops=dict(arrowstyle="-|>", color=GREY, lw=1.4))
        if lab:
            ax.text((xa + xb) / 2 + 0.01, (ya + yb) / 2, lab, fontsize=10, color=MAROON, ha="left", va="center")
    for k, (x, y, t) in NODES.items():
        ax.text(x, y, t, ha="center", va="center", fontsize=11, bbox=BOX)
    ax.text(0.02, 0.04, "long-range ballistic missiles keep the rotation: the left branch plus $\\omega_E$", fontsize=11, color=GREY)
    ax.set_xlim(-0.04, 1.04)
    ax.set_ylim(0, 1.02)
    ax.axis("off")
    save(fig, "fig-06-tree")
