project.py

Created by dan-wallez

Created on December 20, 2024

4.69 KB

Dans l’espace à 3 dimensions, projection orthogonale d’un point M sur une droite ou sur un plan. Les données à saisir sont sous forme fractionnaire. Police python paramétrée à petit.


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 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)
  z = coord("z",nom)
  return(x,y,z)

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

#     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)

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

  print("\nProjection orthogonale dans")
  print("l'espace d'un point M")
  
  print("sur un plan        : choix 0")
  print("sur une droite (AB): choix 1")
  print("Quitter            : choix 2")

  choix = int(input("\nChoix = "))

  if choix == 0 :

    print("\nProjection orthogonale")
    print("d'un point sur un plan")
    
    print("\nSaisie des coordonnées de M")
    xM, yM, zM = saisie("M")

    print("\nSaisie d'une équation cartésienne")
    print("ax+by+cz+d = 0 du plan P")    
    a, b, c, d = coord("a",""), coord("b",""), coord("c",""), coord("d","")

    print("\nPlan (ABC) d'équation cart. :")
    print(a.fstring()+" x + "+b.fstring()+" y + "+c.fstring()+" z + "+d.fstring()+" = 0")
    print("\nPoint à projeter sur le plan (ABC) :")
    print("M("+xM.fstring()+" ; "+yM.fstring()+" ; "+zM.fstring()+")")

    tnum = nul - ( a.fmult(xM) + b.fmult(yM) + c.fmult(zM) + d )
    tden = a.fmult(a) + b.fmult(b) + c.fmult(c)
    t    = tnum.fdiv(tden)

    xH, yH, zH = xM+a.fmult(t), yM+b.fmult(t), zM+c.fmult(t)

    print("\nH projeté orthogonal de M sur le plan :")
    print("H("+xH.fstring()+" ; "+yH.fstring()+" ; "+zH.fstring()+")")
      
    xHdec = round(xH.numerator/xH.denominator,3)
    yHdec = round(yH.numerator/yH.denominator,3)
    zHdec = round(zH.numerator/zH.denominator,3)
    print("Coord de H en décimal,")
    print("précision au millième")
    print("H (",xHdec,";",yHdec,";",zHdec,")\n")

  if choix == 1 :

    print("\nProjection orthogonale")
    print("d'un point sur une droite (AB)")
    print("\nSaisie des points A et B de la droite (AB)")

    print("\nSaisie de A(xA;yA;zA)")
    xA, yA, zA = saisie("A")

    print("\nSaisie de B(xB;yB;zB)")
    xB, yB, zB = saisie("B")

    xAB, yAB, zAB = xB-xA, yB-yA, zB-zA
    
    if xAB.numerator==0 and yAB.numerator==0 and zAB.numerator==0 :
      print("\nA et B confondus\n")
    else :    
      print("\nSaisie de M(xM;yM;zM)")
      xM, yM, zM = saisie("M")

      xAM, yAM, zAM = xM-xA, yM-yA, zM-zA

      AM_scal_AB = xAM.fmult(xAB) + yAM.fmult(yAB) + zAM.fmult(zAB)
      AB_carre   = xAB.fmult(xAB) + yAB.fmult(yAB) + zAB.fmult(zAB)  
      t          = AM_scal_AB.fdiv(AB_carre)

      print("\nDroite (AB) avec :")
      print("A("+xA.fstring()+" ; "+yA.fstring()+" ; "+zA.fstring()+")")
      print("B("+xB.fstring()+" ; "+yB.fstring()+" ; "+zB.fstring()+")\n")
      print("M("+xM.fstring()+" ; "+yM.fstring()+" ; "+zM.fstring()+")")
      print("point à projeter sur la droite (AB)")

      print("\nH projeté orthogonal de M sur (AB) :")
      
      xH, yH, zH = xA+t.fmult(xAB), yA+t.fmult(yAB), zA+t.fmult(zAB)
      print("H("+xH.fstring()+" ; "+yH.fstring()+" ; "+zH.fstring()+")")
      
      xHdec = round(xH.numerator/xH.denominator,3)
      yHdec = round(yH.numerator/yH.denominator,3)
      zHdec = round(zH.numerator/zH.denominator,3)
      print("Coord de H en décimal,")
      print("précision au millième")
      print("H (",xHdec,";",yHdec,";",zHdec,")\n")

  if choix > 1 :
    print("\nAu revoir")
  else :
    bidon = int(input("Saisir 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.