Session2 30/9/22

This commit is contained in:
Debucquoy Anthony 2022-09-30 12:59:47 +02:00
parent b9471f779e
commit 2cbfccb8cc
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
2 changed files with 14 additions and 7 deletions

View File

@ -1,4 +1,5 @@
from math import floor from math import floor, sqrt
def transform_mp_to_abc(m, p): def transform_mp_to_abc(m, p):
"""transforme une équation de la forme y = mx + p to ax + by = c """transforme une équation de la forme y = mx + p to ax + by = c
@ -8,6 +9,7 @@ def transform_mp_to_abc(m, p):
""" """
return -m, 1, p return -m, 1, p
def transform_abc_to_mp(a, b, c): def transform_abc_to_mp(a, b, c):
"""transforme une équation de la forme to ax + by = c to y = mx + p """transforme une équation de la forme to ax + by = c to y = mx + p
@ -16,7 +18,8 @@ def transform_abc_to_mp(a, b, c):
""" """
return -a/b, c return -a/b, c
def droite(p1: tuple,p2: tuple) -> tuple:
def droite(p1: tuple, p2: tuple) -> tuple:
"""retourne un 3-uple d'une droite selon ax+by=c """retourne un 3-uple d'une droite selon ax+by=c
:p1: tuple du point 1 :p1: tuple du point 1
@ -96,8 +99,6 @@ def droite_normale(d, p):
return transform_mp_to_abc(-1/m, y-(-1/m)*x) return transform_mp_to_abc(-1/m, y-(-1/m)*x)
def symetrie_orthogonale(d, p): def symetrie_orthogonale(d, p):
""" retourne la symétrie orthogonale par le point p de la droite d """ retourne la symétrie orthogonale par le point p de la droite d
:returns: symétrie orthogonale :returns: symétrie orthogonale
@ -105,14 +106,19 @@ def symetrie_orthogonale(d, p):
""" """
a, b, c = d a, b, c = d
x, y = p x, y = p
ap, bp, cp = droite_normale(d,p) # perpendiculaire passant par le point ap, bp, cp = droite_normale(d, p) # perpendiculaire passant par le point
xi, yi = intersection((a,b,c), (ap, bp, cp)) xi, yi = intersection((a, b, c), (ap, bp, cp))
return round((2*xi - x)*10)/10, round((2*yi - y)*10)/10 return round((2*xi - x)*10)/10, round((2*yi - y)*10)/10
def distance_droite_point(d, p): def distance_droite_point(d, p):
"""TODO: Docstring for distance_droite_point. """TODO: Docstring for distance_droite_point.
:returns: TODO :returns: TODO
""" """
pass a, b, c = d
x, y = p
ap, bp, cp = droite_normale(d,p) # perpendiculaire passant par le point
xi, yi = intersection((a,b,c), (ap, bp, cp))
return sqrt((xi-x)**2 + (yi-y)**2)

View File

@ -29,6 +29,7 @@ def tests():
test(symetrie_orthogonale, (-0.5, 1, 1.0), (-2, 0), (-2.0, 0.0)) test(symetrie_orthogonale, (-0.5, 1, 1.0), (-2, 0), (-2.0, 0.0))
test(symetrie_orthogonale, (-0.5, 1, 1.0), (3, 4), (4.2, 1.6)) test(symetrie_orthogonale, (-0.5, 1, 1.0), (3, 4), (4.2, 1.6))
test(distance_droite_point, (-0.5, 1, 1.0), (-2, 0), 1.3416407864998741)
test(distance_droite_point, (-0.5, 1, 1.0), (-2, 0), 0.0) test(distance_droite_point, (-0.5, 1, 1.0), (-2, 0), 0.0)