espfct.py

Created by dan-wallez

Created on December 20, 2024

7.01 KB

Menu proposant 4 fonctions dans l’espace à 3 dimensions équation cartésienne d’un plan à partir de 3 points plan médiateur à partir d’un segment équation paramétrique d’une droite dans l’espace équation paramétrique d’un plan Attention les coordonnées des points impérativement sous forme de fraction Utiliser police python en format petit (paramètre de la 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)
  z = coord("z",nom)
  return(x,y,z)

def mise_en_forme_et_affichage(a1,b1,c1,d1):

  pp1  = int(a1.denominator*b1.denominator//pgcd(a1.denominator,b1.denominator))
  pp2  = int(c1.denominator*d1.denominator//pgcd(c1.denominator,d1.denominator))
  ppcm = int(pp1*pp2//pgcd(pp1,pp2))
  mul  = Fraction(ppcm,1)

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

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

  if choix == 0 :
    print("\nUne équation cartésienne")
    print("du plan (A,B,C) :\n")
  else :
    print("\nUne équation cartésienne du")
    print("plan médiateur au segment [AB] :\n")

  if a!=0 and b==0 and c==0 :
    print("Plan parallèle au plan (Oy, Oz)")
    print(a , "x +" , d , "= 0\n")
          
  if a==0 and b!=0 and c==0 :
    print("Plan parallèle au plan (Ox, Oz)")
    print(b , "y +" , d , "= 0\n")

  if a==0 and b==0 and c!=0 :
    print("Plan parallèle au plan (Ox, Oy)")
    print(c , "z +" , d , "= 0\n")

  if a!=0 and b!=0 and c==0 :
    print("Plan parallèle à l'axe  Oz")
    print(a , "x +" , b , "y +" , d , "= 0\n")

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

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

  if a!=0 and b!=0 and c!=0 :
    print("Plan quelconque")
    print(a , "x +" , b , "y +" , c , "z +" , d , "= 0\n")

  if d==0 :
    print("Remarque : L'origine O(0;0;0)")
    print("appartient au plan\n")
  
####    PROGRAMME PRINCIPAL   ####

print("Coord. des points 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 < 4 :

  print("\nEquation cartésienne d'un plan  : choix 0")
  print("Plan médiateur d'un segment     : choix 1")
  print("Equation paramétrique d'un plan : choix 2")
  print("Equation paramétrique")
  print("d'une droite dans l'espace      : choix 3")
  print("Quitter                         : choix 4\n")

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

  if choix == 0 :

    print("\nDétermination d'une équation")
    print("cartésienne du plan passant par")
    print("3 points A,B,C distincts non alignés")

  if choix == 2 :

    print("\nEquation paramétrique d'un plan (ABC)")
    print("3 points A,B,C distincts non alignés")

  if choix == 0 or choix == 2 :
    
    print("\nSaisie de A(xA;yA;zA)")
    xA, yA, zA = saisie("A")
    print("\nSaisie de B(xB;yB;zB)")
    xB, yB, zB = saisie("B")
    print("\nSaisie de C(xC;yC;zC)")
    xC, yC, zC = saisie("C")

    print("\nPlan (A,B,C) avec :\n")
    print("A("+xA.fstring()+" ; "+yA.fstring()+" ; "+zA.fstring()+")")
    print("B("+xB.fstring()+" ; "+yB.fstring()+" ; "+zB.fstring()+")")
    print("C("+xC.fstring()+" ; "+yC.fstring()+" ; "+zC.fstring()+")")

    xAB, yAB, zAB = xB-xA, yB-yA, zB-zA
    xAC, yAC, zAC = xC-xA, yC-yA, zC-zA

    a1 = yAB.fmult(zAC) - zAB.fmult(yAC)
    b1 = zAB.fmult(xAC) - xAB.fmult(zAC)
    c1 = xAB.fmult(yAC) - yAB.fmult(xAC)

    if a1.numerator==0 and b1.numerator==0 and c1.numerator==0 :
      print ("\nPoints alignés ou confondus :")
      print("Infinité de plans possibles\n")
    else :
      if choix == 0 :
        d1 = nul - ( a1.fmult(xA) + b1.fmult(yA) + c1.fmult(zA) )
        mise_en_forme_et_affichage(a1,b1,c1,d1)
      if choix == 2 :
        print("\nUne équation param. du plan (ABC)\n")
        print("x = "+xA.fstring()+" + "+xAB.fstring()+" * t1 + "+xAC.fstring()+" * t2")
        print("y = "+yA.fstring()+" + "+yAB.fstring()+" * t1 + "+yAC.fstring()+" * t2")
        print("z = "+zA.fstring()+" + "+zAB.fstring()+" * t1 + "+zAC.fstring()+" * t2\n")

  if choix == 1 :

    print("\nDétermination d'une équation")
    print("cartésienne du plan médiateur")
    print("au segment [AB]")

    print("\nSaisie des points A et B du segment [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")

    print("\nSegment [AB] avec :")
    print("A("+xA.fstring()+" ; "+yA.fstring()+" ; "+zA.fstring()+")")
    print("B("+xB.fstring()+" ; "+yB.fstring()+" ; "+zB.fstring()+")")

    a1 = xB-xA ; b1 = yB-yA ; c1 = zB-zA

    if a1.numerator==0 and b1.numerator==0 and c1.numerator==0 :
      print("\nLes points A et B sont confondus\n")
    else :
      xI=(xA+xB).fdiv(deux) ; yI=(yA+yB).fdiv(deux) ; zI=(zA+zB).fdiv(deux)
      d1 = nul - (a1.fmult(xI) + b1.fmult(yI) + c1.fmult(zI))
      mise_en_forme_et_affichage(a1,b1,c1,d1)

  if choix == 3 :

    print("\nEquation paramétrique d'une droite (AB)")
    print("2 points A,B distincts")

    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

    print("\nDroite (AB) avec :")
    print("A("+xA.fstring()+" ; "+yA.fstring()+" ; "+zA.fstring()+")")
    print("B("+xB.fstring()+" ; "+yB.fstring()+" ; "+zB.fstring()+")")

    if xAB.numerator==0 and yAB.numerator==0 and zAB.numerator==0 :
      print("\nLes points A et B sont confondus")
      print("(AB) ne peut être une droite\n")
    else :
      print("\nUne équation para. de la droite (AB)\n")
      print("x = "+xA.fstring()+" + "+xAB.fstring()+" * t")
      print("y = "+yA.fstring()+" + "+yAB.fstring()+" * t")
      print("z = "+zA.fstring()+" + "+zAB.fstring()+" * t\n")
      
  if choix > 3 :
    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.