Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. # создаем класс Ломаная
  2. class Poly_chain:
  3.     """ Самостоятельный Poly_chain class """
  4.     #_Vertices={}
  5.     def __init__(self, *_Points,_Points_names=None):
  6.         self._Vertices = {}
  7.         _points_number=len(_Points)
  8.         if _points_number>0:
  9.             if type(_Points_names)!=type((1, 2)) and type(_Points_names) != type([]):
  10.                 counter=1
  11.                 for _P in _Points:
  12.                     self._Vertices['A_'+str(counter)]=_P
  13.                     counter+=1
  14.             else:
  15.                 for counter in range(_points_number):
  16.                     self._Vertices[_Points_names[counter]]=_Points[counter]
  17.  
  18.     def vertices(self):
  19.         return self._Vertices.values()
  20.     def vertices_names(self):
  21.         return self._Vertices.keys()
  22.     def named_vertices(self):
  23.         return self._Vertices
  24.     def plot(self,color='blue'):
  25.         plt.plot([P.x for P in list(self._Vertices.values())],[P.y for P in list(self._Vertices.values())], color)
  26.  
  27.     def plot_annotated(self,color='blue'):
  28.         self.plot(color)
  29.         for V_name in (self.named_vertices().keys()):
  30.             chain_point=self.named_vertices()[V_name]
  31.             plt.annotate('$'+V_name+'$',xy=(chain_point.x, chain_point.y),xytext=(0, 5), textcoords='offset points' )
  32.            
  33.    
  34. class Triangle(Poly_chain):
  35.     """ Потомок Poly_chain class """
  36.     def __init__(self, *_Points,_Points_names=None):
  37.         # Необходимо вызвать метод инициализации родителя.
  38.         # В Python 3.x это делается при помощи функции super()
  39.         super().__init__(*_Points,_Points_names=_Points_names)
  40.         return None
  41.     def plot(self,_color='blue'):
  42.         names = list(self.vertices_names())
  43.         _V=list(self.vertices())+[self._Vertices[names[0]]]
  44.         plt.plot([P.x for P in _V],[P.y for P in _V])
  45.         return None
  46.     def plot_annotate(self, _color='blue'):
  47.         self.plot(color)
  48.         for V_name in (self.named_vertices().keys()):
  49.             chain_point=self.named_vertices()[V_name]
  50.             plt.annotate('$'+V_name+'$',xy=(chain_point.x, chain_point.y),xytext=(0, 5), textcoords='offset points' )
  51.            
  52.     def display(self):
  53.         name = ""
  54.         for i in list(self.vertices_names()):
  55.             name+=i
  56.         print('Треугольник %s' % (name))
  57.         return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement