3 réponses
yg_be
Messages postés
23496
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
26 mars 2025
Ambassadeur
1 571
26 avril 2021 à 16:33
26 avril 2021 à 16:33
bonjour,
ton code est-il complet?
il me retourne des messages d'erreur: np et casteljau sont non définis.
ton code est-il complet?
il me retourne des messages d'erreur: np et casteljau sont non définis.
oui autant pour moi, voici la fonction casteljau :
Et les bibliothèques utilisées :
def casteljau(P,t): n=len(P) temp=P for r in range(n-1,0,-1): for i in range(r): temp[i]=(1-t)*temp[i]+t*temp[i+1] return temp[0]
Et les bibliothèques utilisées :
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation
yg_be
Messages postés
23496
Date d'inscription
lundi 9 juin 2008
Statut
Contributeur
Dernière intervention
26 mars 2025
1 571
26 avril 2021 à 17:41
26 avril 2021 à 17:41
quand je teste, rien ne s'affiche.
ton code est-il complet?
ton code est-il complet?
Alors je remets le code en entier : (Chez moi l'animation se lance normalement il manque juste les points de contrôles comme j'expliquais au début)
Plus la fonction casteljau :
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation from casteljau import casteljau P=np.array([[4.,2.,.0],[0.,-1,0.],[0.,4,0],[4.,1,0]], dtype = float) t = np.linspace(0,1,1000) x=[] y=[] for t in t: p=casteljau(P,t) x.append(p[0]) y.append(p[1]) fig, ax=plt.subplots(figsize=(8, 8)) ax.set(xlim=(-1,4), ylim=(-1,4)) line, = ax.plot([],[]) ax.scatter(P[:,0],P[:,1], color="red", label="Control Points") ax.set_xlabel('x') ax.set_ylabel('y') def animate(i): line.set_data(x[:i],y[:i]) return line, anim = animation.FuncAnimation(fig, animate, frames = len(x)+1, interval =50, blit= True)
Plus la fonction casteljau :
def casteljau(P,t): n=len(P) temp=P for r in range(n-1,0,-1): for i in range(r): temp[i]=(1-t)*temp[i]+t*temp[i+1] return temp[0]