From a35d557b81d9d1432a0a790c0528655be7ed030c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= Date: Wed, 17 Apr 2024 10:34:56 +0200 Subject: [PATCH] TP nombre complexe --- TP Listes Chainées/main.py | 1 + TP Modules Scientifiques/tp3.py | 35 +++++++++-- TP Nombres Complexes/tp15.py | 101 ++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 TP Nombres Complexes/tp15.py diff --git a/TP Listes Chainées/main.py b/TP Listes Chainées/main.py index 6a3189f..6739fe5 100644 --- a/TP Listes Chainées/main.py +++ b/TP Listes Chainées/main.py @@ -82,5 +82,6 @@ def test_polycreux(): print(e) print(pc(1) + pc(0)) + if __name__ == "__main__": main() diff --git a/TP Modules Scientifiques/tp3.py b/TP Modules Scientifiques/tp3.py index ea3bd3d..5951bfd 100644 --- a/TP Modules Scientifiques/tp3.py +++ b/TP Modules Scientifiques/tp3.py @@ -41,13 +41,35 @@ def dessiner_cercle(x, y, r): def cercle_dans_cercle(): plot.axis("equal") - fig, ax = plot.subplots() - for i in range(10): - cercle = dessiner_cercle(0, 0, i + 1) - ax.add_patch(cercle) + for i in range(1, 11): + dessiner_cercle(0, 0, i / 10) plot.show() +def carre_de_cercle(longueur, rayon=1): + # Dessine un carré de coté coté avec des cercles de rayon coté/2 + x = np.linspace(rayon, longueur - rayon, int(longueur / (2 * rayon))) + y = np.linspace(rayon, longueur - rayon, int(longueur / (2 * rayon))) + X, Y = np.meshgrid(x, y) + plot.scatter(X, Y, s=np.pi * (2 * rayon) ** 2) + plot.gca().set_aspect('equal', adjustable='box') + plot.show() + + +def cercle_de_plus_en_plus_petit(): + plot.axis("equal") + x = 0 + for i in range(5): + x -= 2 * i - 1 + dessiner_cercle(x, 0, i) + plot.show() + + +def triangle_avec_cercle(): + for i in range(10): + for j in range(i): + dessiner_cercle(j, i, 0.5) + plot.show() # Jeu de test @@ -63,4 +85,7 @@ cos_a = np.cos(a) # notez qu’il s’agit bien de np.cos() et pas de math.cos( print(cos_a) # affiche [ 0.54030231 -0.66939722 -0.9899925 ] cercle = dessiner_cercle(0, 0, 1) cercle.show() -cercle_dans_cercle() \ No newline at end of file +cercle_dans_cercle() +carre_de_cercle(10, 1) +cercle_de_plus_en_plus_petit() +triangle_avec_cercle() diff --git a/TP Nombres Complexes/tp15.py b/TP Nombres Complexes/tp15.py new file mode 100644 index 0000000..e454bdc --- /dev/null +++ b/TP Nombres Complexes/tp15.py @@ -0,0 +1,101 @@ +import math +import cmath +import turtle +import time + +z = 1 + 3j +print(z.real) +print(z.imag) +print(z.conjugate()) +module = abs(4 + 3j) +print(module) +print(complex(1)) +print(complex(1, 2)) +print(complex(imag=1)) +# complex('1+1 j') +# complex ('1 + 1 j') + +# math.sqrt(-1) +print(cmath.sqrt(-1)) + +c = cmath.phase(complex(-1.0, 0.0)) +print(c) +c = cmath.phase(complex(-1.0, -0.0)) +print(c) + +c = cmath.polar(1j) +print(c) + +c = cmath.exp(1j * cmath.pi / 2) +print(c) + + +def triangle(): + turtle.forward(100) + turtle.left(120) + turtle.forward(100) + turtle.left(120) + turtle.forward(100) + turtle.left(120) + + +def carre(): + turtle.left(45) + turtle.forward(95) + turtle.left(90) + turtle.forward(95) + turtle.left(90) + turtle.forward(95) + turtle.left(90) + turtle.forward(95) + turtle.left(90) + + +def pyntagon(): + for i in range(5): + turtle.forward(100) + turtle.left(72) + + +def hexagon(): + for i in range(6): + turtle.forward(100) + turtle.left(60) + + +def octogon(): + for i in range(8): + turtle.forward(100) + turtle.left(45) + + +def circle(): + for i in range(20): + turtle.forward(10) + turtle.left(360 / 20) + + +def triangle_filled(): + turtle.begin_fill() + triangle() + turtle.end_fill() + + +def triangle_filled_rotation(): + while True: + turtle.begin_fill() + triangle() + turtle.end_fill() + turtle.right(math.degrees(math.pi / 10)) + turtle.clear() + time.sleep(0.5) + + +# triangle() +# carre() +# pyntagon() +# hexagon() +# octogon() +# circle() +# triangle_filled() +triangle_filled_rotation()