import math

def v(t,a,b):
    return a*math.sin(t) - b*math.cos(t)

def troba_equilibri(T1, T2, A, B, eps):    
    vt1 = v(T1,A,B)
    vt2 = v(T2,A,B)
    
    positius = [T1]
    negatius = [T2]
        
    while abs(vt2) >= eps:
        if vt2>0:
            Tprima = max(negatius)
        else:
            Tprima = max(positius)
            
        vtprima = v(Tprima,A,B)
        
        T2 = T2 - (vt2*(T2 - Tprima)) / (vt2 - vtprima)
        vt2 = v(T2,A,B)

        if vt2>0:
            positius.append(T2)
        else:
            negatius.append(T2)
    return T2
