fork download
  1. import math
  2.  
  3.  
  4. # noinspection PyTypeChecker
  5. class Point:
  6. def __init__(self, x, y):
  7. self.x = x
  8. self.y = y
  9.  
  10. def __neg__(self): # operator - (унарный), противоположный вектор
  11. return Point(-self.x, -self.y)
  12.  
  13. def __invert__(self): # operator ~ (унарный), поворот на 90 градусов
  14. return Point(-self.y, self.x)
  15.  
  16. def __add__(self, other): # operator +, сложение векторов
  17. return Point(self.x + other.x, self.y + other.y)
  18.  
  19. def __sub__(self, other): # operator -, вычитание векторов
  20. return Point(self.x - other.x, self.y - other.y)
  21.  
  22. def __truediv__(self, other): # operator /, скалярное произведение
  23. return self.x * other.x + self.y * other.y
  24.  
  25. def __mod__(self, other): # operator %, векторное произведение
  26. return self.x * other.y - self.y * other.x
  27.  
  28. def __mul__(self, other): # operator *, умножение на число
  29. return {self.x * other, self.y * other}
  30.  
  31. def argument(self):
  32. return math.atan2(self.y, self.x)
  33.  
  34. def length(self):
  35. return math.sqrt(self / self)
  36.  
  37.  
  38. a, b = Point(4, 2), Point(10, 12)
  39. c = a + b
  40. print(c.length(), c.argument() / math.pi, '* PI')
  41. print(c / Point(-1, 1), c % Point(-1, 1))
Success #stdin #stdout 0.02s 9492KB
stdin
Standard input is empty
stdout
19.79898987322333 0.25 * PI
0 28