7XP

Untitled

7XP
Feb 12th, 2016
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1.  
  2. class Vector:
  3. def __init__(self,a,b):
  4. self.x = a
  5. self.y = b
  6.  
  7. def __add__(self,other):
  8. return Vector(self.x + other.x,self.y + other.y)
  9.  
  10. def __str__(self):
  11. return '(' + str(self.x) + ',' + str(self.y) + ')'
  12.  
  13. def __mul__(left,right):
  14. return left.x * right.x + left.y * right.y
  15.  
  16. def length(self):
  17. return(self * self) ** 0.5
  18.  
  19. class Point:
  20. def __init__(self,x,y):
  21. self.x = x
  22. self.y = y
  23.  
  24. def __add__(left,right):
  25. return Point(left.x + right.x,left.y + right.y)
  26.  
  27. def __str__(self):
  28. return Vector.__str__(self)
  29.  
  30. def __mul__(left,right):
  31. if type(right) == Vector:
  32. return left.x * right.x + left.y * right.y
  33. else:
  34. return Vector(left.x * right.x + left.x * right.y)
  35.  
  36. def __rmul__(left,right):
  37. return vector.__mul__(left,right)
  38.  
  39. def __neg__(self):
  40. return Vector(-self.x,-self.y)
  41.  
  42. def shift(self,v):
  43. self.x += v.x
  44. self.y += v.y
Add Comment
Please, Sign In to add comment