Vecteurs du plan : première Partie

Algo et Python - Exercice 1

3 min
5
Question 1
On considère l'algorithme écrit en PYTHON ci-dessous :
import\orange{\text{import}} math
def\orange{\text{def}} P(xA,yA,xB,yB)P\left(x_A,y_A,x_B,y_B\right)
                    \;\;\;\;\;\;\;\;\;\;D=D=math.sqrt((xBxA)  2+(yByA)  2)\text{math.sqrt}\left(\left(x_{B} -x_{A} \right) ^{\;**}2+\left(y_{B} -y_{A} \right)^{\;**}2\right)
                    \;\;\;\;\;\;\;\;\;\; return\orange{\text{return}} DD

Que fait cette algorithme.

Correction
Cet algorithme retourne la distance séparant les points de coordonnées (xA,yA)\left(x_A, y_A\right) et (xB,yB)\left(x_B, y_B\right).
Soit (0;i;j)\left(0;\overrightarrow{i} ;\overrightarrow{j} \right) un repère orthonormal du plan et deux points A(xA;yA)A\left(x_{A} ;y_{A} \right) et B(xB;yB)B\left(x_{B} ;y_{B} \right). La distance ABAB est donnée par la formule :
  • AB=(xBxA)2+(yByA)2AB=\sqrt{\left(x_{B} -x_{A} \right)^{2} +\left(y_{B} -y_{A} \right)^{2} }