cartesienne.py

Created by dan-wallez

Created on September 27, 2022

3.92 KB

Donne une équation cartésienne du plan à partir de 3 points distincts et non alignés.


from math import *

def nb_chif_apres_virg(chaine):
  compteur = 0
  trouve_virg = False
  for i in range(len(chaine)):
    if chaine[i] == "." :
      trouve_virg = True
    else :
      if trouve_virg :
        compteur += 1
  return (compteur)

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

####    PROGRAMME PRINCIPAL   ####
def cartesienne():
  tab = []

  print("\nSaisie des coordonnées du point A")
  xA = input("xA = ")
  tab.append(nb_chif_apres_virg(xA))
  yA = input("yA = ")
  tab.append(nb_chif_apres_virg(yA))
  zA = input("zA = ")
  tab.append(nb_chif_apres_virg(zA))

  print("\nSaisie des coordonnées du point B")
  xB = input("xB = ")
  tab.append(nb_chif_apres_virg(xB))
  yB = input("yB = ")
  tab.append(nb_chif_apres_virg(yB))
  zB = input("zB = ")
  tab.append(nb_chif_apres_virg(zB))

  print("\nSaisie des coordonnées du point C")
  xC = input("xC = ")
  tab.append(nb_chif_apres_virg(xC))
  yC = input("yC = ")
  tab.append(nb_chif_apres_virg(yC))
  zC = input("zC = ")
  tab.append(nb_chif_apres_virg(zC))

  max = int(0)
  for i in range(len(tab)):
    if tab[i] > max:
      max = tab[i]
  mult = int(10**max)

  xA = round(eval(xA)*mult)
  yA = round(eval(yA)*mult)
  zA = round(eval(zA)*mult)
  xB = round(eval(xB)*mult)
  yB = round(eval(yB)*mult)
  zB = round(eval(zB)*mult) 
  xC = round(eval(xC)*mult)
  yC = round(eval(yC)*mult)
  zC = round(eval(zC)*mult)

  xAB = xB-xA
  yAB = yB-yA
  zAB = zB-zA

  xAC = xC-xA
  yAC = yC-yA
  zAC = zC-zA

  if (xAB*xAC+yAB*yAC+zAB*zAC)**2 == (xAB**2+yAB**2+zAB**2)*(xAC**2+yAC**2+zAC**2):    
    print ("\nPoints alignés ou confondus")
    print ("Infinité de plans possibles\n")
  else :
    print ("\nPoints distincts et non alignes")
    print ("\nEquation cartesienne du plan :")

    stop = False
    
    if (xA==xB==xC):
      a = 1           
      b = 0
      c = 0
      d = - xA/mult
      print("\nPlan parallèle au plan formé par les axes 0y et 0z\n")
      print("x + " + str(d) + " = 0")
      stop = True

    if (yA==yB==yC):
      a = 0            
      b = 1
      c = 0
      d = - yA/mult
      print("\nPlan parallèle au plan formé par les axes 0x et 0z\n")
      print("y + " + str(d) + " = 0")
      stop = True

    if (zA==zB==zC):
      a = 0           
      b = 0
      c = 1
      d = - zA/mult
      print("\nPlan parallèle au plan formé par les axes 0x et 0y\n")
      print("z + " + str(d) + " = 0")
      stop = True
      
    if not stop :

      if xAB*zAC - xAC*zAB != 0 :

        a = yAC*zAB - yAB*zAC
        b = xAB*zAC - xAC*zAB
        c = yAB*xAC - yAC*xAB

        d = -(a*xA + b*yA + c*zA) / mult

        if c==0 :
          print("\nPlan parallèle à l'axe Oz\n")
          d1  = pgcd(a,b)
          div = pgcd(d1,d)
          a = int(a/div)
          b = int(b/div)
          d = int(d/div)
          print(str(a) + " x + " + str(b) + " y + " + str(d) + " = 0")

        if a==0 :
          print("\nPlan parallèle à l'axe Ox\n")    
          d2  = pgcd(c,d)
          div = pgcd(b,d2)
          b = int(b/div)
          c = int(c/div)
          d = int(d/div)
          print(str(b) + " y + " + str(c) + " z + " + str(d) + " = 0")

        if a!=0 and c!=0 :
          print("\nPlan quelconque\n")
          d1  = pgcd(a,b)
          d2  = pgcd(c,d)
          div = pgcd(d1,d2)
          a = int(a/div)
          b = int(b/div)
          c = int(c/div)
          d = int(d/div)
          print(str(a) + " x + " + str(b) + " y + " + str(c) + " z + " + str(d) + " = 0")

      else :
        
        xBC = xC-xB
        yBC = yC-yB
        zBC = zC-zB

        print("\nPlan parallèle à l'axe Oy\n")      
        a = zAB*yBC - zBC*yAB        
        b = 0
        c = xBC*yAB - xAB*yBC
        d = -(a*xA + b*yA + c*zA) / mult
        d2  = pgcd(c,d)
        div = pgcd(a,d2)
        a = int(a/div)
        c = int(c/div)
        d = int(d/div)
        print(str(a) + " x + " + str(c) + " z + " + str(d) + " = 0")

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.