"""Lecture 10, a pitot-static probe and the three instruments it feeds: the total pressure from the forward hole, the
static pressure from the side holes, the airspeed indicator (their difference), the altimeter and the Mach meter.
A schematic, no numbers. Writes img/fig-10-pitot-static.png."""
from matplotlib.patches import FancyBboxPatch, Circle, FancyArrowPatch
from _visual import plt, save, MAROON, BLUE, INK, GREY, GREEN

if __name__ == "__main__":
    fig, ax = plt.subplots(figsize=(10, 5.4))
    # the free stream
    for y in (3.9, 4.6, 5.3):
        ax.add_patch(FancyArrowPatch((0.1, y), (1.3, y), arrowstyle="-|>", mutation_scale=16, color=GREY, lw=1.4))
    ax.text(0.1, 5.7, "free stream: $V$, $p$, $T$", fontsize=12, color=GREY)
    # probe: outer tube (static) and inner tube (total)
    ax.add_patch(FancyBboxPatch((1.6, 4.25), 4.2, 0.7, boxstyle="round,pad=0.02,rounding_size=0.35", fc="#eee6d8", ec=INK, lw=1.6))
    ax.plot([1.62, 5.8], [4.6, 4.6], color=MAROON, lw=3)
    ax.add_patch(Circle((1.62, 4.6), 0.07, color=MAROON))
    ax.text(1.5, 3.75, "forward hole:\ntotal pressure $p_t$", fontsize=11.5, color=MAROON, ha="left", va="top")
    for x in (3.0, 3.3, 3.6):
        ax.plot([x, x], [4.95, 5.05], color=BLUE, lw=2.5)
    ax.text(3.3, 5.3, "side holes: static pressure $p$", fontsize=11.5, color=BLUE, ha="center")
    # lines to instruments: static (blue) from above to all three, total (maroon) from below to two
    YC, RC = 2.5, 0.55
    ax.plot([5.8, 10.4], [4.85, 4.85], color=BLUE, lw=2.2)
    for x in (7.0, 8.7, 10.4):
        ax.plot([x, x], [4.85, YC + RC], color=BLUE, lw=2.2)
    ax.plot([5.8, 6.2, 6.2, 10.4], [4.6, 4.6, 1.6, 1.6], color=MAROON, lw=2.2)
    for x in (7.0, 10.4):
        ax.plot([x, x], [1.6, YC - RC], color=MAROON, lw=2.2)
    for x, lab, sub in ((7.0, "airspeed\nindicator", "$p_t-p$"), (8.7, "altimeter", "$p$"), (10.4, "Mach\nmeter", "$p_t/p$")):
        ax.add_patch(Circle((x, YC), RC, fc="white", ec=INK, lw=1.8, zorder=3))
        ax.text(x, YC, sub, ha="center", va="center", fontsize=11.5, zorder=4)
        ax.text(x, 1.35, lab, ha="center", va="top", fontsize=11.5)
    ax.set_xlim(0, 11.2)
    ax.set_ylim(0.2, 6.0)
    ax.set_aspect("equal")
    ax.axis("off")
    save(fig, "fig-10-pitot-static")
