From 3e52ef1f50aa707f27c76839123b62efb22346ff Mon Sep 17 00:00:00 2001 From: "antoine.perederii" Date: Wed, 22 Feb 2023 14:45:04 +0100 Subject: [PATCH] ajout des maths tp5 --- Maths/tp/Bezier/tp5/tp5.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Maths/tp/Bezier/tp5/tp5.py b/Maths/tp/Bezier/tp5/tp5.py index 5c18166..d445d2c 100644 --- a/Maths/tp/Bezier/tp5/tp5.py +++ b/Maths/tp/Bezier/tp5/tp5.py @@ -14,7 +14,8 @@ def stop_ici(): input() exit() - +from time import time +debut = time() def CastelJauUnPoint(t, P): P = P.copy() N = P.shape[0] - 1 @@ -28,6 +29,40 @@ def traceBezierCastelJau(P,K): allt = np.linspace(0,1,K) allFt = np.array([CastelJauUnPoint(t,P) for t in allt]) plt.plot(allFt[:,0], allFt[:,1]) +# met des valeurs aléatoire a P +P = np.random.rand(4,2) +K = 1000000000 +traceBezierCastelJau(P,K) + +fin = time() +temps = fin - debut +print("Durée de calcul pour Castel: ", temps) + + + +from time import time +debut = time() +from scipy.special import binom +def BezierFormuleUnPoint(t,P): + N = P.shape[0]-1 + Ft = np.zeros(2) + for i in range(N+1): + Ft += binom(N,i)*t**i*(1-t)**(N-i)*P[i] + return Ft + +def traceBezierFormule(P,K): + allt = np.linspace(0,1,K) + allFt = np.array([BezierFormuleUnPoint(t,P) for t in allt]) + plt.plot(allFt[:,0], allFt[:,1]) + +# met des valeurs aléatoire a P +P = np.random.rand(4,2) +K = 1000000000 +traceBezierFormule(P,K) + +fin = time() +duree = fin - debut +print("Durée de calcul pour Bezier un point : ", duree) stop_ici() \ No newline at end of file