calculvectoriel.py

Created by squirreline

Created on June 03, 2018

2.26 KB

Ce script regroupe de nombreuses fonctions concernant les vecteurs ( produit scalaire, norme, colinéarité, équation de droite avec un vecteur normal…)


from math import *

def vecteur(xa,ya,xb,yb):
 X=xb-xa
 Y=yb-ya
 print("X=",X,"Y=",Y)
 return X,Y
 
def colineaire(xa,ya,xb,yb,xc,yc,xd,yd,vecteuroupoint):
  if (vecteuroupoint==pi):
    return xa*yb-xb*ya==0
  else:
    print("coordonees vecteur 1")
    X,Y = vecteur(xa,ya,xb,yb)
    print("coordonees vecteur 2")
    XX,YY = vecteur(xc,yc,xd,yd)
    return X*YY-XX*Y==0
    
def produitscalaire(XA,YA,XB,YB,XC,YC,vecteuroupoint):
  if (vecteuroupoint==pi):#pi_sert_juste_de_marqueur
    #rappel_des_coordonnees_pour_les_verifier
    print("X=",XA,"Y=",YA,"X'=",XB,"Y'=",YB)
    produitscalaire=XA*XB+YA*YB
    print(produitscalaire)
  else:
    print("XA=",XA,"YA=",YA,"XB=",XB,"YB=",YB,"XC=",XC,"YC=",YC)
    #calcul_des_coordonnees_des_vecteurs
    print("coordonees vecteur 1")
    X,Y = vecteur(XA,YA,XB,YB)
    print("coordonees vecteur 2")
    XX,YY= vecteur(XA,YA,XC,YC)
    
    produitscalaire=X*XX+Y*YY
    print("produitscalaire=",produitscalaire)
    
def norme(xa,ya,xb,yb,vecteuroupoint):
  if (vecteuroupoint==pi):
    print("X=",xa,"Y=",ya)
    J=xa**2+ya**2
    print("sqrt(",J,")")#donne_la_valeur_exacte_de_la_racine_carree
    norme=sqrt(J)
    print (norme)
  else:
    X,Y = vecteur(xa,ya,xb,yb)
    J=X**2+Y**2
    print("sqrt(",J,")")
    norme=sqrt(J)
    print(norme)
    
def angle(AB,AC,angle):
 print ("AB=",AB,"AC=",AC,"angle=",angle)
 produitscalaire=AB*AC*cos(angle)
 print (produitscalaire)
 
def figure(u,v,w,tp):#tp indique s'il s'agit d'un triangle ou d'un parallelogramme
 if (tp==pi):
   print("1/2(u**2 + v**2 - (u-v)**2","il_s'agit_d'un_triangle")#rappel de la formule
   print ("1/2(",u**2,"+",v**2,"-",w**2,")")
   produitscalaire=1/2*(u**2+v**2-w**2)
   print (produitscalaire)
 else:
   print("1/2((u+v)**2 - u**2 -v**2)","il_s'agit_d'un_parallelogramme")
   print ("1/2(",w**2,"-",u**2,"-",u**2,")")
   produitscalaire=1/2*(w**2-u**2-v**2)
   print (produitscalaire)
  
def eqcartdroite(xa,ya,xb,yb,xc,yc,vecteuroupoint):
  if vecteuroupoint==pi:
    print("vecteurnormal(",xa,";",ya,")")
    print("point(",xb,";",yb,")")
    v=xa*xb+ya*yb
    c=-v
    print(xa,"x+",ya,"y+",c)
  else:
    X,Y = vecteur(xa,ya,xb,yb)
    print("vecteurnormal(",X,";",Y,")")
    print("point(",xc,";",yc,")")
    v=X*xc+Y*yc
    c=-v
    print(X,"x+",Y,"y+",c)
  

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.