from math import cos,sin,pi
import matplotlib.pyplot as plt

m = float(input("Entrer le coefficient directeur 'm' : "))
p = float(input("Entrer l'ordonnée à l'origine 'p' : "))
t = float(input("Entrer l'angle de la rotation de centre O (en degré) : "))
t = t*pi/180

a = m*cos(t) + abs( sin(t) )
b = m*abs( sin(t) ) - cos(t)
c = p*sin(t)*a - p*cos(t)*b

if b<0:
    bs = " - "+str(abs(b))
else:
    bs = " + "+str(b)

if c<0:
    cs = " - "+str(abs(c))
else:
    cs = " + "+str(c)

print(str(a)+"x"+bs+"y"+cs+" = 0")

# tracé

fig = plt.figure()

plt.axis('equal')
plt.grid(axis='both',color='lightgray', linestyle='--')


x = [-8 , 8]
y = [0 , 0]
plt.plot(x,y,linewidth=1,color='black')

x = [0 , 0]
y = [-6 , 6]
plt.plot(x,y,linewidth=1,color='black')


x = [-5 , 5]
y = [-5*m+p , 5*m+p]

plt.plot(x,y,label='(d)')

y = [-a*(-5)/b-c/b , -a*5/b-c/b]

plt.plot(x,y,color='r',label="(d')")

legend = fig.legend(loc='upper center', shadow=True, fontsize='x-large')

plt.show()