Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # создаем класс Ломаная
- class Poly_chain:
- """ Самостоятельный Poly_chain class """
- #_Vertices={}
- def __init__(self, *_Points,_Points_names=None):
- self._Vertices = {}
- _points_number=len(_Points)
- if _points_number>0:
- if type(_Points_names)!=type((1, 2)) and type(_Points_names) != type([]):
- counter=1
- for _P in _Points:
- self._Vertices['A_'+str(counter)]=_P
- counter+=1
- else:
- for counter in range(_points_number):
- self._Vertices[_Points_names[counter]]=_Points[counter]
- def vertices(self):
- return self._Vertices.values()
- def vertices_names(self):
- return self._Vertices.keys()
- def named_vertices(self):
- return self._Vertices
- def plot(self,color='blue'):
- plt.plot([P.x for P in list(self._Vertices.values())],[P.y for P in list(self._Vertices.values())], color)
- def plot_annotated(self,color='blue'):
- self.plot(color)
- for V_name in (self.named_vertices().keys()):
- chain_point=self.named_vertices()[V_name]
- plt.annotate('$'+V_name+'$',xy=(chain_point.x, chain_point.y),xytext=(0, 5), textcoords='offset points' )
- class Triangle(Poly_chain):
- """ Потомок Poly_chain class """
- def __init__(self, *_Points,_Points_names=None):
- # Необходимо вызвать метод инициализации родителя.
- # В Python 3.x это делается при помощи функции super()
- super().__init__(*_Points,_Points_names=_Points_names)
- return None
- def plot(self,_color='blue'):
- names = list(self.vertices_names())
- _V=list(self.vertices())+[self._Vertices[names[0]]]
- plt.plot([P.x for P in _V],[P.y for P in _V])
- return None
- def plot_annotate(self, _color='blue'):
- self.plot(color)
- for V_name in (self.named_vertices().keys()):
- chain_point=self.named_vertices()[V_name]
- plt.annotate('$'+V_name+'$',xy=(chain_point.x, chain_point.y),xytext=(0, 5), textcoords='offset points' )
- def display(self):
- name = ""
- for i in list(self.vertices_names()):
- name+=i
- print('Треугольник %s' % (name))
- return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement