# -*- coding: utf-8 -*-
# Calcul pour la résolution du triangle rectangle.
# v.10

'''
-------------------------------------------------
Pour les besoins du calcul les nom de variables
doivent êtres global pour tout le programme
-------------------------------------------------
rep => nombre de réponse
base, cote, hypo => les trois cotés du triangle 
ang_b, ang_c => les deux angles pour le calcul
ang_h étant = à 90 degrès
Pent => pente, coni => cônicité ou double pente
perim => perimètre, surf => surface
volum => volume du demi-cône ou triangle vue de coté
vol_cone => volume du cône le coté étant le rayon
-------------------------------------------------
'''

print("Résolution du triangle rectangle!")
print("=================================")
# print()
#----------------------------------------pour mémoire

# 2pi = 6.283185307179586476925286766559
# 90° / 180 * pi = 1.5707963267948966 radians

#----------------------------------------importation math

from math import sin, cos, tan, asin, acos, atan
global pi
pi = 3.1415926535897932384626433832795

#----------------------------------------déclaration des variables globales

rep = 0
base = 0.0
cote = 0.0
hypo = 0.0
ang_b = 0.0
ang_c = 0.0
pent = 0.0
coni = 0.0
perim = 0.0
surf = 0.0
vol_cone = 0.0
volum = 0.0

#-----------------------------questions début du programme

def question():
    global pi
    global rep
    global ang_c
    global ang_b
    global base
    global cote
    global hypo
    global pent
    global coni
    global perim
    global surf
    global volum
    global vol_cone

    base = input ("Longueur de la base, si non zéro ? ")
    try :
        base = float(base)
    except :
        base = "0"
        base = float(base)
    if base != 0.0 :
        rep +=1

    ang_b = input ("Valeur de l'angle de la base en degrés, si non zéro ? ")
    try :
        ang_b = float(ang_b)
    except :
        ang_b = "0"
        ang_b = float(ang_b)
    if ang_b != 0.0 :
        ang_b = ang_b / 180 * pi   # convertion des degrés en radians
        rep +=1
    if rep > 1 :
        return    

    cote = input ("Longueur du coté, si non zéro ? ")
    try :
        cote = float(cote)
    except :
        cote = "0"
        cote = float(cote)
    if cote != 0.0 :
        rep +=1
    if rep > 1 :
        return

    ang_c = input ("Valeur de l'angle du coté en degrés, si non zéro ? ")
    try :
        ang_c = float(ang_c)
    except :
        ang_c = "0"
        ang_c = float(ang_c)
    if ang_c != 0.0 :
        ang_c = ang_c / 180 * pi    # convertion des degrés en radians
        rep +=1
    if rep > 1 :
        return

    hypo = input ("Valeur de l'hypoténuse, si non zéro ? ")
    try :
        hypo = float(hypo)
    except :
        hypo = "0"
        hypo = float(hypo)
    if hypo != 0.0 :
        rep +=1
    if rep > 1 :
        return

    pent = input ("Valeur de la pente en pourcentage, si non zéro ? ")
    try :
        pent = float(pent)
    except :
        pent = "0"
        pent = float(pent)
    if pent != 0.0 :
#        pent = pent               # pourcentage pas besoin de convertion
        rep +=1
    if rep > 1 :
        return

    coni = input ("Valeur de la cônicité en pourcentage, si non zéro ? ")
    try :
        coni = float(coni)
    except :
        coni = "0"
        coni = float(coni)
    if coni != 0.0 :
#        coni = coni               # pourcentage pas besoin de convertion
        rep +=1
    if rep > 1 :
        return

#-----------------------------fonction solve calcul

def solve():
    global ang_c
    global ang_b
    global base
    global cote
    global hypo
    global pente
    global coni

    if pent != 0.0 :
        ang_c = atan(pent/100)

    if coni != 0.0 :
        ang_c = atan(coni/200)

    if ang_b != 0.0 and ang_c != 0.0 :
        print()
        print("les arguments fournis ne permettent pas le calcul des longueurs")
        return

    if base != 0.0 and ang_c != 0.0 :
        hypo = base / cos(ang_c)
        cote = base * tan(ang_c)
        return

    if cote != 0.0 and ang_b != 0.0 :
        hypo = cote / cos(ang_b)
        base = cote * tan(ang_b)
        return

    if hypo != 0.0 and ang_c != 0.0 :
        base = hypo * sin(ang_c)
        cote = hypo * cos(ang_c)
        return

    if hypo != 0.0 and ang_b != 0.0 :
        base = hypo * sin(ang_b)
        cote = hypo * cos(ang_b)
        return

    if cote != 0.0 and ang_c != 0.0 :
        hypo = cote / sin(ang_c)
        base = cote / tan(ang_c)
        return

    if base != 0.0 and ang_b != 0.0 :
        hypo = base / sin(ang_b)
        cote = base / tan(ang_b)
        return

    if base != 0.0 and cote != 0.0 : # 3  4  5
        ang_c = atan(cote / base)
        hypo = base / cos(ang_c)
        return

    if base != 0.0 and hypo != 0.0 :
        ang_c = acos(base / hypo)
        cote = base * tan(ang_c)
        return

    if cote != 0.0 and hypo != 0.0 :
        ang_c = asin(cote / hypo)
        base = cote / tan(ang_c)
        return

#-----------------------------fonction calcul résolution

def calcul():
    global pi
    global ang_c
    global ang_b
    global base
    global cote
    global hypo
    global pent
    global coni
    global perim
    global surf
    global volum
    global vol_cone

    if ang_b == 0.0 :
        ang_b = 90 / 180 * pi - ang_c

    if ang_c == 0.0 :
        ang_c = 90 / 180 * pi- ang_b

    if pent == 0.0 :
        pent = tan(ang_c) * 100 # ou atan(cote/base) en radians

    if coni == 0.0 :
        coni = tan(ang_c) * 200

    perim = hypo + base + cote
    surf = base * cote / 2

    vol_cone = pi * base ** 2 * hypo

    volum = vol_cone / 2

#-----------------------------main

question()
solve()
calcul()
print()

#-----------------------------affichage
#   ici les angles sont reconvertis en degrés
if rep > 1 :
    print()
    print("la base du triangle est..........: ", round(base, 2))
    print("  ", base)
    print("le côté du triangle est..........: ", round(cote, 2))
    print("  ", cote)
    print("l'hypoténuse est.................: ", round(hypo, 2))
    print("  ", hypo)
    print("l'angle de la base est...........: ", round(ang_b / pi * 180, 2), "degrés")
    print("  ", ang_b / pi * 180)
    print("l'angle du côté est de...........: ", round(ang_c / pi * 180, 2), "degrés")
    print("  ", ang_c / pi * 180)
    print()
    print("le périmètre de ce triangle est..: ", round(perim, 2))
    print("la surface en est de : ",round(surf, 2))
    print("le volume du demi-cône est de....: ", round(volum, 2))
    print("le volume du cône est de.........: ", round(vol_cone, 2))
    print()
    print("la pente est de..................: ", round(pent, 2), "%")
    print("la cônicité est..................: ", round(coni, 2), "%")
else :
    print()
    print("Désolé pas asser d'argument! pour permettre le calcul")

print()
print("----------------------")
bye = (input ("Entrer pour Sortir...!"))