1import matplotlib.pyplot as plt
2
3class Triangulo:
4 '''
5 Classe Triangulo ABC.
6 '''
7
8 num_lados = 3
9
10 def __init__(self, A, B, C):
11
12 self.A = A
13 self.B = B
14 self.C = C
15
16 def plot(self):
17 fig = plt.figure()
18 ax = fig.add_subplot()
19
20 ax.plot([self.A[0], self.B[0]],
21 [self.A[1], self.B[1]], marker='o', color='blue')
22 ax.text((self.A[0]+self.B[0])/2,
23 (self.A[1]+self.B[1])/2, 'c')
24 ax.plot([self.B[0], self.C[0]],
25 [self.B[1], self.C[1]], marker='o', color='blue')
26 ax.text((self.B[0]+self.C[0])/2,
27 (self.B[1]+self.C[1])/2, 'a')
28 ax.plot([self.C[0], self.A[0]],
29 [self.C[1], self.A[1]], marker='o', color='blue')
30 ax.text((self.A[0]+self.C[0])/2,
31 (self.A[1]+self.C[1])/2, 'b')
32
33 ax.text(self.A[0], self.A[1], 'A')
34 ax.text(self.B[0], self.B[1], 'B')
35 ax.text(self.C[0], self.C[1], 'C')
36 ax.grid()
37 plt.show()
38
39tria = Triangulo((0., 0.),
40 (2., 0.),
41 (1., 1.))
42tria.plot()