from pygasflow.shockwave import PressureDeflectionLocus
from pygasflow.interactive import PressureDeflectionDiagram

M1 = 3
theta_2 = 20
theta_3 = -15

loc1 = PressureDeflectionLocus(M=M1, label="1")
loc2 = loc1.new_locus_from_shockwave(theta_2, label="2")
loc3 = loc1.new_locus_from_shockwave(theta_3, label="3")

phi, p4_p1 = loc2.intersection(loc3)
print("Intersection between locus M2 and locus M3 happens at:")
print("Deflection Angle [deg]:", phi)
print("Pressure ratio to freestream:", p4_p1)

d = PressureDeflectionDiagram(
    title="Intersection of shocks of opposite families"
)
d.add_locus(loc1)
d.add_locus(loc2)
d.add_locus(loc3)
d.add_path((loc1, theta_2), (loc2, phi))
d.add_path((loc1, theta_3), (loc3, phi))
d.add_state(
    phi, p4_p1, "4=4'",
    background_fill_color="white",
    background_fill_alpha=0.8)
d.move_legend_outside()
d.y_range = (0, 18)
d.show_figure()