1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
import numpy as np
import matplotlib.pyplot as plt
#%%Dessin général
N1=1.000272 #Différentes variables (tout les xmin,ymin...) pour paramétrer facilement le schéma)
N2=1.33298
amplitude=2. #Variables idéales à (2;10;-60;10;-30;30;400)
periode=10.
ymin=-60
ymax=10
xmin=-30
xmax=30
nombre_rayons=400
rayons_frontiere=True #Affiche ou non les rayons bornant chaque cône
points_lum_max=True
vague=lambda x: amplitude*np.cos(x*2*np.pi/periode) #Equation de la vague
derivee_vague=lambda x: -amplitude*(2*np.pi/periode)**2*np.sin(x*2*np.pi/periode) #Equation de la dérivée
def angle(t):
'''Fonction qui renvoi l'angle du rayon d'abscisse t une fois réfléchi par la vague
On a développé sin(arctan(x)) pour minimiser les calculs'''
tangante = derivee_vague(t)
a_reflechi=np.arcsin(N1/N2*tangante/(1+ tangante**2)**0.5)
return a_reflechi - np.arctan(tangante)
def droite(t):
'''Fonction qui, pour l'équation de la droite du rayon réfléchi,
trouve x tel que f(x)=ymin (utile pour ensuite tracer le rayons avec deux coordonées'''
i=angle(t)
coef_dir=1/np.tan(i) #calcul du coefficient directeur de la droite réfléchie
return (ymin-vague(t))/coef_dir +t
plt.clf()
fig=plt.figure(1)
X=np.linspace(1.5*xmin,1.5*xmax,nombre_rayons) #coefficint 1.5 arbitraire : affiche les rayons hors(xmin,xmax)
Y=vague(X)
#Configuration de ax1, contient tout le graphique
ax1=fig.add_subplot(111)
plt.xlim((xmin,xmax))
plt.ylim((ymin,ymax))
ax1.plot(X,Y,color='#33adff') #Tracé de la vague
for i in X:
ax1.plot([i,droite(i)],[vague(i),ymin],alpha=0.3,color='whitesmoke') #alpha pour définir l'opacité
ax1.fill_between(X,Y,y2=ymax,color='#e6ffff') #rempli d'une certaine couleur un espace
ax1.fill_between(X,Y,y2=ymin,color='#4d94ff')
#Configuration de ax2, contient les rayons frontières, ne doit pas maquer ax1
ax2=fig.add_subplot(110)
ax2.patch.set_facecolor('None')
ax2.axis('off')
if rayons_frontiere:
for k in range(2*int(1.5*xmin//periode),2*int(1.5*xmax//periode+1)):
x=periode/4. + k*periode/2.
ax2.plot([x,droite(x)],[vague(x),ymin],color='#ff5050',alpha=0.8)
plt.xlim((xmin,xmax))
plt.ylim((ymin,ymax))
#Evenements pour afficher ou pas les rayons frontières en temp réel
def onclick(event):
''''Lorsque l'on clique, fait disparaître les rayons frontières'''
ax2.cla()
ax2.patch.set_facecolor('None')
ax2.axis('off')
plt.draw()
def press(event):
''' Lorque l'on appuie sur une touche, trace les rayons frontière'''
if rayons_frontiere:
for k in range(2*int(1.5*xmin//periode),2*int(1.5*xmax//periode+1)):
x=periode/4. + k*periode/2.
ax2.plot([x,droite(x)],[vague(x),ymin],color='#ff5050',alpha=0.8)
plt.xlim((xmin,xmax))
plt.ylim((ymin,ymax))
plt.draw() |
Partager