Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Vector:
- def __init__(self,a,b):
- self.x = a
- self.y = b
- def __add__(self,other):
- return Vector(self.x + other.x,self.y + other.y)
- def __str__(self):
- return '(' + str(self.x) + ',' + str(self.y) + ')'
- def __mul__(left,right):
- return left.x * right.x + left.y * right.y
- def length(self):
- return(self * self) ** 0.5
- class Point:
- def __init__(self,x,y):
- self.x = x
- self.y = y
- def __add__(left,right):
- return Point(left.x + right.x,left.y + right.y)
- def __str__(self):
- return Vector.__str__(self)
- def __mul__(left,right):
- if type(right) == Vector:
- return left.x * right.x + left.y * right.y
- else:
- return Vector(left.x * right.x + left.x * right.y)
- def __rmul__(left,right):
- return vector.__mul__(left,right)
- def __neg__(self):
- return Vector(-self.x,-self.y)
- def shift(self,v):
- self.x += v.x
- self.y += v.y
Add Comment
Please, Sign In to add comment