# -*- coding: utf-8 -*-
# Chapitre 14 — Trajectoires d'un projectile selon l'angle (CORRIGÉ)
# Pour chaque angle de tir, on construit la trajectoire point par point
# avec les équations horaires, et on relève la portée.

import math
import matplotlib.pyplot as plt

g = 9.81
v0 = 20.0                     # vitesse initiale (m/s)
angles = [15, 30, 45, 60, 75]  # degrés
legendes = ["15°", "30°", "45°", "60°", "75°"]

print("angle (°) | portée (m)")
for i in range(len(angles)):
    alpha = angles[i]
    a = math.radians(alpha)
    vx0 = v0 * math.cos(a)    # décomposition de v0  # À COMPLÉTER
    vz0 = v0 * math.sin(a)    # décomposition de v0  # À COMPLÉTER

    xs = [0.0]
    zs = [0.0]
    t = 0.0
    while zs[len(zs) - 1] >= 0.0:
        t = t + 0.01
        xs.append(vx0 * t)
        zs.append(vz0 * t - 0.5 * g * t * t)
    print("angle", alpha, ": portée", xs[len(xs) - 1], "m")
    plt.plot(xs, zs, label=legendes[i])

plt.xlabel("x (m)")
plt.ylabel("z (m)")
plt.axhline(0, color="k", lw=0.8)
plt.legend()
plt.grid(True)
plt.title("Quelle portée pour quel angle ?")
plt.show()
