first commit

This commit is contained in:
Debucquoy
2022-09-29 17:42:52 +02:00
commit 9386728e96
8 changed files with 272 additions and 0 deletions

Binary file not shown.

90
29sept/ex2-1/droite.py Normal file
View File

@ -0,0 +1,90 @@
def droite(p1: tuple,p2: tuple) -> tuple:
"""retourne un 3-uple d'une droite selon ax+by=c
:p1: tuple du point 1
:p2: tuple du point 2
:returns: 3-uple (a,b,c) tq ax+by=c
"""
x1, y1 = p1
x2, y2 = p2
if p1 == p2:
return
if x2-x1 == 0:
return 1, 0, 0
a = -(y2-y1)/(x2-x1)
c = a*x1
b = (-a*x2 + c) / y2
return a, b, c
def appartient(d, p):
"""
:d: equation d'une droite
:p: point
:returns: true si point est dans droite
"""
a, b, c = d
x, y = p
return a*x + b*y == c
def paralleles(d1, d2):
"""
:d1: droite 1
:d2: droite 2
:returns: true si d1 et d2 sont paralleles sinon false
"""
a1, b1, c1 = d1
a2, b2, c2 = d2
return a1/b1 == a2/b2
def intersection(d1, d2):
"""Trouve le point d'intersection
:d1: droite 1
:d2: droite 2
:returns: retourne le point d'intersection sinon None
"""
a1, b1, c1 = d1
a2, b2, c2 = d2
if paralleles(d1, d2):
return # paralleles donc pas d'intersection
y = (c2*a1 - a2*c1) / (-a2*b1 + b2*a1)
x = (c1 - b1*y)/ a1
return x, y
def droite_normale(d, p):
"""TODO: trouve la normale dune droite passant par un point.
:d: droite
:p: point
:returns: retourne la normale de la droite passant par le point
"""
def symetrie_orthogonale(d, p):
"""TODO: Docstring for symetrie_orthogonale(d, p.
:returns: TODO
"""
pass
def distance_droite_point(d, p):
"""TODO: Docstring for distance_droite_point.
:returns: TODO
"""
pass

View File

@ -0,0 +1,37 @@
from droite import *
def test(function, p1, p2, exp_result):
fun_result = function(p1, p2)
if fun_result == exp_result:
print(f"{function.__name__}({p1}, {p2}) == {exp_result} --- SUCCESS!")
else:
print(f"{function.__name__}({p1}, {p2}) == {exp_result} --- ERROR! (result was:{fun_result})")
def tests():
test(droite, (-2, 0), (1, 1.5), (-0.5, 1, 1.0))
test(droite, (0, -3), (0, 5), (1, 0, 0))
test(droite, (0, -1), (0, -1), None)
test(appartient, (-0.5, 1, 1.0), (-2, 0), True)
test(appartient, (-0.5, 1, 1.0), (1, 1.5), True)
test(appartient, (-0.5, 1, 1.0), (0, -1), False)
test(paralleles, (0, 1, 1), (0, 2, 3), True)
test(paralleles, (-0.5, 1, 1.0), (0, 2, 3), False)
test(intersection, (-0.5, 1, 1.0), (0, 2, 3), (1.0, 1.5))
test(intersection, (0, 1, 1), (0, 2, 3), None)
test(droite_normale, (-0.5, 1, 1.0), (-2, 0), (2.0, 1, -4.0))
test(droite_normale, (-0.5, 1, 1.0), (3, 4), (2.0, 1, 10.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), (2.0, 1, 10.0))
test(distance_droite_point, (-0.5, 1, 1.0), (-2, 0), 0.0)
if __name__ == "__main__":
tests()