planfct.py

Created by dan-wallez

Created on December 20, 2024

7.18 KB

Menu (5 fonctions dans le plan) 1 : équation cartésienne; 2 : droite médiatrice d’un segment; 3 : équation paramétrique de droite; 4 :projection orthogonal d’un point sur une droite; 5 ; intersection de 2 droites. Attention coordonnées sous forme de fraction et police python paramétrée en format petit sur calculatrice


class Fraction:
  def __init__(self,x,y):
    self.numerator=int(x)
    self.denominator=int(y)
  def __add__(self,fract):
    return Fraction(self.numerator*fract.denominator + self.denominator*fract.numerator , self.denominator*fract.denominator).simplify()
  def fmult(self,fract):
    return Fraction(self.numerator*fract.numerator , self.denominator*fract.denominator).simplify()
  def fdiv(self,fract):
    return Fraction(self.numerator*fract.denominator , self.denominator*fract.numerator).simplify()
  def __sub__(self,fract):
    return Fraction(self.numerator*fract.denominator - self.denominator*fract.numerator , self.denominator*fract.denominator).simplify()
  def simplify(self):
    divc = pgcd(self.numerator,self.denominator)
    a=self.numerator // divc
    b=self.denominator // divc
    return Fraction(a,b)
  def fstring(self):
    self=self.simplify()
    if self.denominator==1 :
      return "{}".format(self.numerator)
    else :
      return "{}/{}".format(self.numerator,self.denominator)

def pgcd(a,b):
  if b == 0:
    return a
  else:
    r = a%b
    return pgcd(b,r)

def coord(coord,n):
  num = int(input("\nNumérateur   de " + coord + n + " = "))
  den = int(input(  "Dénominateur de " + coord + n + " = "))
  return(Fraction(num,den))

def saisie(nom):
  x = coord("x",nom)
  y = coord("y",nom)
  return(x,y)

def mise_en_forme_et_affichage(a1,b1,c1):
  
  pp1  = int(a1.denominator*b1.denominator//pgcd(a1.denominator,b1.denominator))
  ppcm = int(pp1*c1.denominator//pgcd(pp1,c1.denominator))
  mul  = Fraction(ppcm,1)

  a = a1.fmult(mul).numerator
  b = b1.fmult(mul).numerator
  c = c1.fmult(mul).numerator

  div1 = pgcd(a,b)
  div  = pgcd(div1,c)
  
  a//=div ; b//=div ; c//=div

  if a!=0 and b==0 :
    print("Droite parallèle à l'axe Oy")
    print(a , "x +" , c , "= 0")

  if a==0 and b!=0 :
    print("Droite parallèle à l'axe Ox")
    print(b , "y +" , c , "= 0")

  if a!=0 and b!=0 :
    print("Droite quelconque")
    print(a , "x +" , b , "y +" , c , "= 0")
  
  if c==0 :
    print("Remarque : La droite passe")
    print("par l'origine O(0;0;0)")

#########     PROGRAMME PRINCIPAL

print("\nIMPORTANT POUR LA SAISIE")
print("Si donnée sous forme de fraction :")
print("Numérateur   entier relatif")
print("Dénominateur entier relatif non nul")

nul  = Fraction(0,1)
deux = Fraction(2,1)

choix = 0
while choix > -1 and choix < 5 :

  print("\nEquation cartésienne de droite  : choix 0")
  print("Droite médiatrice d'un segment  : choix 1")
  print("Equation paramétrique de droite : choix 2")
  print("Projection orthogonale")
  print("d'un point M sur une droite     : choix 3")
  print("Intersection de deux droites    : choix 4")
  print("Quitter                         : choix 5")

  choix = int(input("Choix = "))

  if choix == 0 :
    print("\nEquation cartésienne")
    print("d'une droite (AB) dans le plan")
    print("\nSaisie des points A et B de la droite (AB)")

  if choix == 1 :
    print("\nDroite médiatrice d'un")
    print("segment [AB] dans le plan")
    print("\nSaisie des points A et B du segment [AB]")

  if choix == 2 :
    print("\nEquation paramétrique")
    print("d'une droite (AB) dans le plan")
    print("\nSaisie des points A et B de la droite (AB)")

  if choix == 3 :
    print("\nProjection orthogonale d'un point M")
    print("sur une droite (AB) dans le plan")
    print("\nSaisie des points A et B de la droite (AB)")


  if choix == 0 or choix == 1 or choix == 2 or choix == 3:

    print("\nSaisie de A(xA;yA)")
    xA, yA = saisie("A")
    print("\nSaisie de B(xB;yB)")
    xB, yB = saisie("B")

    xAB, yAB = xB-xA, yB-yA

    if xAB.numerator==0 and yAB.numerator==0 :
      print("\nA("+xA.fstring()+" ; "+yA.fstring()+")")
      print("B("+xB.fstring()+" ; "+yB.fstring()+")")
      print("\nLes points A et B sont confondus")
    else :
      if choix == 0 :
        a1, b1 = yAB, nul - xAB
        c1 = nul - (a1.fmult(xA) + b1.fmult(yA))
        print("\nUne équation cartésienne de la droite (AB)")
        print("avec A("+xA.fstring()+" ; "+yA.fstring()+")")
        print("et   B("+xB.fstring()+" ; "+yB.fstring()+")\n")
        mise_en_forme_et_affichage(a1,b1,c1)
      if choix == 1 :
        a1, b1 = xAB, yAB
        xI, yI = (xA+xB).fdiv(deux), (yA+yB).fdiv(deux)
        c1 = nul - (a1.fmult(xI)+ b1.fmult(yI))
        print("\nUne équation cartésienne de la")
        print("droite médiatrice du segment [AB]")
        print("avec A("+xA.fstring()+" ; "+yA.fstring()+")")
        print("et   B("+xB.fstring()+" ; "+yB.fstring()+")\n")
        mise_en_forme_et_affichage(a1,b1,c1)
      if choix == 2 :
        print("\nDroite (AB) avec A("+xA.fstring()+" ; "+yA.fstring()+") et B("+xB.fstring()+" ; "+yB.fstring()+")")
        print("\nUne équation param. de la droite (AB) :")
        print("x = "+xA.fstring()+" + "+xAB.fstring()+" * t")
        print("y = "+yA.fstring()+" + "+yAB.fstring()+" * t")
      if choix == 3 :
        print("\nSaisie de M(xM;yM)")
        xM, yM = saisie("M")
        
        xAM, yAM = xM-xA, yM-yA
        AM_scal_AB = xAM.fmult(xAB) + yAM.fmult(yAB)
        AB_carre   = xAB.fmult(xAB) + yAB.fmult(yAB)
        t          =  AM_scal_AB.fdiv(AB_carre)

        print("\nDroite (AB) avec :")
        print("A("+xA.fstring()+" ; "+yA.fstring()+")")
        print("B("+xB.fstring()+" ; "+yB.fstring()+") et")
        print("M("+xM.fstring()+" ; "+yM.fstring()+") point à projeter sur (AB)")
        
        print("\nH projeté orthogonal de M sur la droite :")
        xH = xA + t.fmult(xAB)
        yH = yA + t.fmult(yAB)  
        print("H ("+xH.fstring()+" ; "+yH.fstring()+")")

        xHdec = round(xH.numerator/xH.denominator,3)
        yHdec = round(yH.numerator/yH.denominator,3)
        print("Coordonnées en décimal de H")
        print("(précision au millième):")
        print("H (",xHdec," ; ",yHdec,")")        

  if choix == 4:
    print("\nIntersection de droites")
    print("(d1) et (d2) dans le plan")
    print("\nSaisie des équations cartésiennes")
    print("ax+by+c = 0 des droites (d1) et (d2)")
    print("Si les équations de (d1),(d2) inconnues")
    print("déterminez les équations cart. dans le plan")
    print("de (d1), (d2) à partir de points  : choix 0")

    print("\nDroite (d1)")
    a1, b1, c1 = coord("a1",""), coord("b1",""), coord("c1","")
    print("\nDroite (d2)")
    a2, b2, c2 = coord("a2",""), coord("b2",""), coord("c2","")

    print("\n(d1) : "+a1.fstring()+" x + "+b1.fstring()+" y + "+c1.fstring()+" = 0")
    print("(d2) : "+a2.fstring()+" x + "+b2.fstring()+" y + "+c2.fstring()+" = 0")

    den = a1.fmult(b2) - a2.fmult(b1)
    if den.numerator == 0 :
      print("\nDroites parallèles")
    else :
      xI = (c2.fmult(b1) - c1.fmult(b2)).fdiv(den)
      yI = (a2.fmult(c1) - a1.fmult(c2)).fdiv(den)
      
      print("\nI point d'intersection de (d1) et (d2)")

      print("I ("+xI.fstring()+" ; "+yI.fstring()+")")

      xIdec = round(xI.numerator/xI.denominator,3)
      yIdec = round(yI.numerator/yI.denominator,3)
      print("Coordonnées en décimal de I")
      print("(précision au millième) :")
      print("I (",xIdec," ; ",yIdec,")")

  if choix > 4 :
    print("\nAu revoir")
  else :
    bidon = int(input("\nSaisir un chiffre pour revenir au menu : "))
# Type your text here

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.