from math import sqrt
############################################################################################################
def Newton(P,t): # P=[a,b,c]=polynôme X^3+a*X^2+b*X+c ; t=valeur initiale
t0=t+1
while abs(t-t0)>1E-10:
t0=t; t=t-(t**3+P[0]*t**2+P[1]*t+P[2])/(3*t**2+2*P[0]*t+P[1])
return t
def Solve(P): # P=[a,b,c]=polynôme X^3+a*X^2+b*X+c
x0=-P[0]/3; y0=x0**3+P[0]*x0**2+P[1]*x0+P[2]; Delta=P[0]**2-3*P[1];
if Delta<0:
return [Newton(P,x0)]
else:
d=sqrt(Delta); x1=x0-d/3; x2=x0+d/3; y1=x1**3+P[0]*x1**2+P[1]*x1+P[2]; y2=x2**3+P[0]*x2**2+P[1]*x2+P[2]
if y1<0:
return [Newton(P,x2+1)]
if y2>0:
return [Newton(P,x1-1)]
return [Newton(P,x1-1),Newton(P,x0),Newton(P,x2+1)]
############################################################################################################
def Eq_Droite(A,B): # A ; B = [x,y]
n=sqrt((A[0]-B[0])**2+(A[1]-B[1])**2)
return [(B[1]-A[1])/n,(A[0]-B[0])/n,(A[1]*B[0]-A[0]*B[1])/n]
# [a,b,c] où Droite:ax+by+c=0 avec a^2+b^2=1
def Eq_Parabole(D,F): # D=[a,b,c]=Droite:ax+by+c=0 avec a^2+b^2=1 ; F=[x,y]=Foyer
return [D[1],-D[0],-2*(F[0]+D[0]*D[2]),-2*(F[1]+D[1]*D[2]),F[0]**2+F[1]**2-D[2]**2]
# [a,b,c,d,e] où Parabole:(ax+by)^2+dx+ey+f=0
def Eq_Tangente_Parabole(P): # P=[a,b,c,d,e]=Parabole:(ax+by)^2+dx+ey+f avec a^2+b^2=1
d=P[0]*P[3]-P[1]*P[2]
return [(P[3]**2/4-P[1]**2*P[4])/d,(2*P[0]*P[1]*P[4]-P[2]*P[3]/2)/d,(P[2]**2/4-P[0]**2*P[4])/d,-P[1],P[0]]
# [a,b,c,d,e] où D:ux+vy+w=0 est une tangente à P ssi au^2+buv+cv^2+duw+evw=0
def Tangente_Commune(T1,T2): #T1,T2=[a,b,c,d,e]=Eqaution au^2+buv+cv^2+duw+evw=0
d=T1[0]*T2[3]-T1[3]*T2[0]; a=(T1[0]*T2[4]-T1[4]*T2[0]+T1[1]*T2[3]-T1[3]*T2[1])/d
b=(T1[1]*T2[4]-T1[4]*T2[1]+T1[2]*T2[3]-T1[3]*T2[2])/d; c=(T1[2]*T2[4]-T1[4]*T2[2])/d
S=Solve([a,b,c]); R=[]
for s in S:
d=sqrt(s**2+1); a=s/d; b=1/d;
R.append([a,b,-(T1[0]*a**2+T1[1]*a*b+T1[2]*b**2)/(T1[3]*a+T1[4]*b)]);
return R
M1=[2,1]; N1=[3,-2]; F1=[5,4]; M2=[-2,3]; N2=[3,0]; F2=[-1,0]
T1=Eq_Tangente_Parabole(Eq_Parabole(Eq_Droite(M1,N1),F1))
T2=Eq_Tangente_Parabole(Eq_Parabole(Eq_Droite(M2,N2),F2))
print(Tangente_Commune(T1,T2))
Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 3 invités
Tu pars déja ?
Identification
Pas encore inscrit ?
Ou identifiez-vous :