Salut,
Dans ce cas :
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from math import sqrt,asin,pi
from time import clock
def MinMax():
print (" +++ Choix des périmètres mini et maxi +++\n")
while 1:
mini=input("Périmètre minimum souhaité ? ")
try:
minp=int(mini)
break
except ValueError:
print ("Entrée incorrecte. Veuillez recommencer S.V.P..\n\n")
while 1:
maxi=input("Perimètre maximum souhaité ? ")
try:
maxp=int(maxi)+1
if maxp<=minp:
print ("Erreur,le maximum doit être supérieur au mini. Veuillez recommencer S.V.P..\n\n")
else:
break
except ValueError:
print ("Entrée incorrecte. Veuillez recommencer S.V.P..\n\n")
print("\n\n")
return minp,maxp
def Genere_IsoC(minp,maxp):
Trg=[]
for p in range(minp,maxp):
for b in range(1,maxp):
a=p-b
if a>b and a%2==0 and asin(b/a)<pi/4:
Trg.append((p,b,a//2,a//2))
return Trg
def Genere_IsoAutre(minp,maxp):
Trg=[]
for p in range(minp,maxp):
for b in range(1,maxp):
a=p-b
if a>b and a%2==0:
Trg.append((p,b,a//2,a//2))
return Trg
def circonscrit(minp,maxp):
Trg=Genere_IsoC(minp,maxp)
candidats=[]
print ("\n ** Triangles isocèles ayant un rayon du cercle circonscrit entier **\n\n")
for p,b,a,a1 in Trg:
R=a**2/sqrt(4*a**2-b**2)
if float(int(R))==R:
h=sqrt(a**2-b**2/4)
l=h-R
d=sqrt((b//2)**2+l**2)
if d==R:
print ("Périmètre :","%5i" %p," * ","%4i" %b,"%4i" %a,"%4i" %a," rayon :","%4i" % int(R))
return
def inscrit(minp,maxp):
Trg=Genere_IsoAutre(minp,maxp)
print ("\n ** Triangles isocèles et centre du cercle inscrit **\n\n")
for p,b,a,a1 in Trg:
SI=sqrt(a**2-b**2/4)
fin=int(SI)+1
for MI in range(1,fin):
MS = SI-MI
if 2*a*MI==b*MS:
PM=sqrt(MI**2+b**2/4)
if float(int(PM))==PM:
print ("Périmètre :","%5i" %p," * ","%4i" %b,"%4i" %a,"%4i" %a," --- ","%4i" %MS,"%4i" %int(PM),"%4i" %int(PM)," Rayon :","%4i" %int(MI))
return
def gravite(minp,maxp):
Trg=Genere_IsoAutre(minp,maxp)
print ("\n ** Triangles isocèles et centre de gravité **\n")
for p,b,a,a1 in Trg:
SI=sqrt(a**2-b**2/4)
if float(int(SI))==SI and SI%3==0:
MI=SI//3 # M est le centre de gravité du triangle
PM=sqrt(MI**2+b**2/4)
if float(int(PM))==PM: #si la longueur PM est un entier, alors M convient
print ("Périmètre :","%5i" %p," * ","%4i" %b,"%4i" %a,"%4i" %a," --- ",int(SI-MI),int(PM),int(PM))
return
def orthocentre(minp,maxp):
Trg=Genere_IsoC(minp,maxp)
# S,P,R,I : noms génériques du sommet principal et des 2 autres sommets, et du milieu de [PR]
# Placement d'un repère orthonormé de centre P et tel que [PR] vest sur l'axe des abscisses
print ("\n ** Triangles isocèles et orthocentre **\n")
for p,b,a,a1 in Trg:
SI=sqrt(a**2-b**2/4)
if float(int(SI))==SI:
SI=int(SI)
for MI in range(1,SI):
x,y=b/2,MI #coordonnées du vecteur PM
x1,y1=-b/2,SI #coordonnées du vecteur RS
if x*x1+y*y1==0: # condition d'orthogonalité de 2 vecteurs
SM,PM=SI-MI,sqrt(MI**2+b**2/4)
print ("Périmètre :","%5i" %p," * ","%4i" %b,"%4i" %a,"%4i" %a," --- ","%4i" %SM,"%4i" %int(PM),"%4i" %int(PM)," *** MI =","%4i" %MI,"<> SI =","%4i" %SI)
return
def ScalenesSimples(minp,maxp):
Trg=[]
# Triangles à cotés entiers classés par pérmètres croissants
for p in range(minp,maxp): # p est le périmètre
for b in range(1,maxp): # b sera limité bien avant maxp
a=(p-b)//2 # division euclidienne
if a<b:
break # b est trop grand, passer à la valeur suivante de b
c=p-b-a
while 1: # boucle pour tous les triangles tels que b<=a<=c
if c>=b+a: # le triangle n'existe pas
break # donc sortie de la boucle while...
if not (a==b or a==c or b==c):
Trg.append((p,a,c,b))
a-=1 #triangle suivant de même périmètre
c+=1
if a<b:
break
return Trg
def ScalenesAigus(minp,maxp):
Trg=[]
# Triangles à cotés entiers classés par pérmètres croissants
for p in range(minp,maxp): # p est le périmètre
for b in range(1,maxp): # b sera limité bien avant maxp
a=(p-b)//2 # division euclidienne
if a<b:
break # b est trop grand, passer à la valeur suivante de b
c=p-b-a
while 1: # boucle pour tous les triangles tels que b<=a<=c
if c>=b+a: # le triangle n'existe pas
break # donc sortie de la boucle while...
if not (a==b or a==c or b==c):
a2,b2,c2=a**2,b**2,c**2
if a2+b2-c2>0 and a2+c2-b2>0 and b2+c2-a2>0:
Trg.append((p,a,c,b))
a-=1 #triangle suivant de même périmètre
c+=1
if a<b:
break
return Trg
def circonscrit_scalène(minp,maxp):
tp_d=clock()
Trg=ScalenesAigus(minp,maxp)
dur=round(clock()-tp_d,1)
print ("\n ** Triangles Scalènes ayant un rayon du cercle circonscrit entier **\n")
for p,a,c,b in Trg:
s4=sqrt(p*(p-2*a)*(p-2*b)*(p-2*c))
R = (a*b*c)/s4
if float(int(R))==R:
print ("Périmètre :","%5i" %p," * ","%4i" %a,"%4i" %b,"%4i" %c," rayon :","%4i" % int(R))
print ("\n +++ Temps de calcul avant affichage :",int(dur)//60,"min",dur%60,"s +++\n")
return
def gravite_scalene(minp, maxp):
tp_d=clock()
Trg=ScalenesSimples(minp,maxp)
dur=round(clock()-tp_d,1)
print ("\n** Triangles Scalènes ayant un Centre de gravité à distances entières des sommets **\n")
for p,a,c,b in Trg:
a2,b2,c2=a**2,b**2,c**2
AM=sqrt(2*(c2+b2)-a2)/3
if float(int(AM))==AM:
BM=sqrt(2*(c2+a2)-b2)/3
if float(int(BM))==BM:
CM=sqrt(2*(b2+a2)-c2)/3
if float(int(BM))==BM:
print("Périmètre :","%5i" % p," *", "%4i" % a,"%4i" % c,"%4i" % b," --- ","%4i" % int(AM),"%4i" % int(BM), "%4i" % int(CM))
print ("\n +++ Temps de calcul avant affichage :",int(dur)//60,"min",dur%60,"s +++\n")
return
def orthocentre_scalenes(minp,maxp):
tp_d=clock()
Trg=ScalenesAigus(minp,maxp)
dur=round(clock()-tp_d,1)
print ("\n** Triangles Scalènes ayant leur orthocentre à distances entières des sommets **\n")
for p,a,c,b in Trg:
s4=sqrt(p*(p-2*a)*(p-2*b)*(p-2*c))
a2,b2,c2=a**2,b**2,c**2
AM=a*(b2+c2-a2)/s4
if float(int(AM))==AM:
BM=b*(a2+c2-b2)/s4
if float(int(BM))==BM:
CM=c*(a2+b2-c2)/s4
if float(int(CM))==CM:
print("Périmètre :","%5i" % p," *", "%4i" % a,"%4i" % c,"%4i" % b," --- ","%4i" % int(AM),"%4i" % int(BM), "%4i" % int(CM))
print ("\n +++ Temps de calcul avant affichage :",int(dur)//60,"min",dur%60,"s +++\n")
return
# Menu Pricipal
# Dictionnaire de noms de fonctions
Dic_Fonc={"1":circonscrit,"2":inscrit,"3":gravite,"4":orthocentre,"5":circonscrit_scalène,"6":gravite_scalene,\
"7":orthocentre_scalenes}
##########
stoppe=0
while not stoppe:
Trg,Dico,nb,nombre=[],{},0,0
print (" **************************")
print (" * *")
print (" * Triangles *")
print (" * Points particuliers *")
print (" * v. 2.3 *")
print (" * *")
print (" **************************")
print ()
print ()
print (" Voulez-vous lister les triangles :")
print ()
print (" 1. Isocèles où M est le centre du cercle circonscrit")
print (" 2. Isocèles où M est le centre du cercle inscrit")
print (" 3. Isocèles où M est le centre de gravité")
print (" 4. Isocèles où M est l'orthocentre")
print (" 5. Scalènes où M est le centre du cercle circonscrit")
print (" 6. Scalènes où M est le centre de gravité")
print (" 7. Scalènes où M est l'othocentre")
print ()
print (" 0. Quitter le programme")
print ()
print (" ** Votre choix : ** ",end="")
while 1:
chx=input()
if chx=="0":
stoppe=1
elif chx in "1 2 3 4 5 6 7" :
print ("\n")
minp,maxp=MinMax()
Dic_Fonc[chx](minp,maxp)
else:
print ("Réponses attendues : 0,1,2,3,4,5,6n. Veuillez recommencer s'il vous plaît...")
print ("\n")
print ("\n")
break
print ("\n")
print ("\n")
print(" A la prochaine !")
La recherche avec l'orthocentre a été intégrée...
@+