# -*- coding: utf-8 -*-
# Ch11 - Interférences : addition de deux sinusoïdes de même période.
# Modélise deux ondes arrivant en un point de l'écran (fentes d'Young).
# Corrigé.
import math
# import matplotlib.pyplot as plt

A = 1.0            # amplitude commune
T = 1.0            # période commune
phi = math.pi      # déphasage de s2 (rad) : essayer 0, math.pi/2, math.pi

temps = []
s1 = []
s2 = []
S = []

t = 0.0
while t <= 3.0:
    y1 = A * math.sin(2 * math.pi * t / T)
    y2 = A * math.sin(2 * math.pi * t / T + phi)
    y = y1 + y2
    temps.append(t)
    s1.append(y1)
    s2.append(y2)
    S.append(y)
    t = t + 0.02

S_min = S[0]
S_max = S[0]
for valeur in S:
    if valeur < S_min:
        S_min = valeur
    if valeur > S_max:
        S_max = valeur
amplitude_S = (S_max - S_min) / 2

print("phi =", phi, "rad  ->  amplitude de la somme =", amplitude_S)

#plt.plot(temps, s1, linestyle="--", label="s1")
#plt.plot(temps, s2, linestyle=":", label="s2")
#plt.plot(temps, S, linewidth=2, label="S = s1 + s2")
#plt.xlabel("t"); plt.ylabel("signal"); plt.legend(); plt.grid(True)
#plt.show()
