"""Lecture 34: schematic of a lifting capsule seen from behind, flying into the page, with its lift vector at bank angles
of 0, 60 and 120 deg and the vertical and sideways parts. No numbers beyond the cosines and sines.
Writes img/fig-34-bank-vector.png."""
import numpy as np
from matplotlib.patches import Circle
from _visual import plt, save, MAROON, BLUE, GREEN, INK, GREY

BANKS = [0.0, 60.0, 120.0]


def parts(sig_deg):
    """(sideways, vertical) parts of a unit lift at bank sig."""
    return np.sin(np.radians(sig_deg)), np.cos(np.radians(sig_deg))


if __name__ == "__main__":
    fig, axs = plt.subplots(1, 3, figsize=(10.5, 4.3))
    for ax, s in zip(axs, BANKS):
        side, up = parts(s)
        ax.add_patch(Circle((0, 0), 0.34, facecolor="#e6e1d6", edgecolor=INK, lw=1.8))
        ax.plot(0, 0, "+", color=GREY, ms=9)
        ax.annotate("", xy=(1.1 * side, 1.1 * up), xytext=(0, 0), arrowprops=dict(arrowstyle="-|>", color=MAROON, lw=3))
        if abs(side) > 0.01:
            for (x, y), c in (((0, 1.1 * up), GREEN), ((1.1 * side, 0), BLUE)):
                ax.annotate("", xy=(x, y), xytext=(0, 0), arrowprops=dict(arrowstyle="-|>", color=c, lw=2))
                ax.plot([x, 1.1 * side], [y, 1.1 * up], color=GREY, lw=0.8, ls=":")
        ax.axhline(0, color=GREY, lw=0.7, ls="--", zorder=0)
        word = "up" if up > 0 else "DOWN"
        ax.set_title(f"$\\sigma$ = {s:.0f}°", fontsize=13)
        ax.text(0.15, -1.2, f"vertical: {abs(up):.2f} $L$ {word}\nsideways: {side:.2f} $L$" + ("" if side == 0 else " right"),
                ha="center", fontsize=11.5)
        ax.set_xlim(-0.9, 1.25); ax.set_ylim(-1.4, 1.3); ax.set_aspect("equal"); ax.axis("off")
    fig.text(0.5, 0.0, "red: lift $L$    green: vertical part    blue: sideways part", ha="center", fontsize=11.5)
    save(fig, "fig-34-bank-vector")
