Boutons de projection de l'axe 3D

main
Gaël Pongnot 2 years ago
parent db48f791f7
commit e9a79c5bf7
  1. 65
      MLI_vectorielle.py

@ -12,7 +12,6 @@ PI = np.pi
N_PTS = 400 N_PTS = 400
class TriPlot_TimeAxe(Axes): class TriPlot_TimeAxe(Axes):
"""Classe d'axe temporel""" """Classe d'axe temporel"""
@ -308,8 +307,17 @@ class TriPlot_3DAxe(Axes3D):
self.theta self.theta
) )
def projX(self, event=None):
self.view_init(89.99, -90.01, 'y')
self.get_figure().canvas.draw()
def projY(self, event=None):
self.view_init(0, -90.01, 'y')
self.get_figure().canvas.draw()
def projZ(self, event=None):
self.view_init(0, 0, 'y')
self.get_figure().canvas.draw()
return return
class TriPlot: class TriPlot:
@ -334,7 +342,8 @@ class TriPlot:
self.fig, [0.5, 0.1, 0.4, 0.4]) self.fig, [0.5, 0.1, 0.4, 0.4])
self.axe3D = TriPlot_3DAxe(self.v_max, self.phi, self.axe3D = TriPlot_3DAxe(self.v_max, self.phi,
self.fig, [0.5, 0.6, 0.4, 0.4]) self.fig, [0.5, 0.6, 0.4, 0.4])
self.axes = [self.vectaxe, self.timeaxe, self.axe3D]
# -- Curseurs de réglage
self.amp_slider = Slider( self.amp_slider = Slider(
ax=plt.axes([0.01, 0.1, 0.03, 0.8]), ax=plt.axes([0.01, 0.1, 0.03, 0.8]),
label="Tension\nefficace", label="Tension\nefficace",
@ -351,16 +360,35 @@ class TriPlot:
valinit=self.phi, valinit=self.phi,
orientation="horizontal" orientation="horizontal"
) )
# -- Bouton de remise à zéro
self.reset_button = Button( self.reset_button = Button(
ax=plt.axes([0.95, 0.01, 0.03, 0.03]), ax=plt.axes([0.95, 0.01, 0.03, 0.03]),
label='Reset', label='Reset'
hovercolor='0.975'
) )
# -- Cases de cocher pour les parametres de visibilité
self.parameters_check = CheckButtons( self.parameters_check = CheckButtons(
ax=plt.axes([0.9, 0.8, 0.1, 0.2]), ax=plt.axes([0.9, 0.8, 0.1, 0.2]),
labels=["Projection", "Valeur efficace"] labels=["Projection", "Valeur efficace"]
) )
# -- Boutons de projection de l'axe 3D
self.projX_button = Button(
ax=plt.axes([0.9, 0.67, 0.1, 0.03]),
label='Axe réel'
)
self.projY_button = Button(
ax=plt.axes([0.9, 0.635, 0.1, 0.03]),
label='Axe imaginaire'
)
self.projZ_button = Button(
ax=plt.axes([0.9, 0.60, 0.1, 0.03]),
label='Plan complexe'
)
# Listes et dictionaires
self.axes = [self.vectaxe, self.timeaxe, self.axe3D]
self.sliders = [self.amp_slider, self.phi_slider] self.sliders = [self.amp_slider, self.phi_slider]
self.parameters = {} self.parameters = {}
@ -371,54 +399,77 @@ class TriPlot:
return return
def setup(self): def setup(self):
# Appels aux fonctions de configuration initiale de chaque axe
for axe in self.axes: for axe in self.axes:
axe.setup() axe.setup()
# Configuration des widgets pour lancer un rafraichissement en cas de modification
for slider in self.sliders: for slider in self.sliders:
slider.on_changed(self.refresh) slider.on_changed(self.refresh)
self.reset_button.on_clicked(self.reset)
self.parameters_check.on_clicked(self.refresh) self.parameters_check.on_clicked(self.refresh)
self.reset_button.on_clicked(self.reset)
self.projX_button.on_clicked(self.axe3D.projX)
self.projY_button.on_clicked(self.axe3D.projY)
self.projZ_button.on_clicked(self.axe3D.projZ)
# Affichage du Copyright
self.fig.text(0.01, 0.98, "Gaël Pongnot, CC-BY-NC", size=8) self.fig.text(0.01, 0.98, "Gaël Pongnot, CC-BY-NC", size=8)
# Configuration de la fenêtre (Qt)
win = self.fig.canvas.window() win = self.fig.canvas.window()
win.setMinimumSize(1200, 800) win.setMinimumSize(1200, 800)
win.showMaximized() win.showMaximized()
return return
def refresh(self, val=None): def refresh(self, val=None):
# Lecture des nouvelles valeurs
self.set_veff(self.amp_slider.val) self.set_veff(self.amp_slider.val)
self.set_phi(self.phi_slider.val) self.set_phi(self.phi_slider.val)
self.set_parameters(self.parameters_check.get_status()) self.set_parameters(self.parameters_check.get_status())
# Rafraichissement des axes
for axe in self.axes: for axe in self.axes:
axe.refresh() axe.refresh()
# Actualisation de l'affichage
self.fig.canvas.draw() self.fig.canvas.draw()
return return
def reset(self, event=None): def reset(self, event=None):
# Remise à zéro des sliders -> déclenche un rafraichissement
for slider in self.sliders: for slider in self.sliders:
slider.reset() slider.reset()
return return
def set_vmax(self, v_max): def set_vmax(self, v_max):
# Modification des attributs liés à v_max
self.v_max = v_max self.v_max = v_max
self.v_eff = v_max/np.sqrt(2) self.v_eff = v_max/np.sqrt(2)
self.v_ref = self.v_max*np.cos(self.phasor) self.v_ref = self.v_max*np.cos(self.phasor)
# Application du changement aux axes
for axe in self.axes: for axe in self.axes:
axe.set_vmax(self.v_max) axe.set_vmax(self.v_max)
return return
def set_veff(self, v_eff): def set_veff(self, v_eff):
# Transfert de la modification à set_vmax
self.set_vmax(np.sqrt(2)*v_eff) self.set_vmax(np.sqrt(2)*v_eff)
return return
def set_phi(self, phi): def set_phi(self, phi):
# Modification des attributs liés à phi
self.phi = phi self.phi = phi
# Application du changement aux axes
for axe in self.axes: for axe in self.axes:
axe.set_phi(self.phi) axe.set_phi(self.phi)
return return
def set_parameters(self, p): def set_parameters(self, p):
# Modification des attributs liés à p
self.parameters["projection"] = p[0] self.parameters["projection"] = p[0]
self.parameters["v_eff"] = p[1] self.parameters["v_eff"] = p[1]
# Application du changement aux axes
for axe in self.axes: for axe in self.axes:
axe.set_parameters(self.parameters) axe.set_parameters(self.parameters)
return return

Loading…
Cancel
Save