diff --git a/main.py b/main.py index 104be10..6af30ca 100644 --- a/main.py +++ b/main.py @@ -1,2 +1,24 @@ +import math class Vector2d: - pass \ No newline at end of file + def __init__(self,x, y): + self.x = x + self.y = y + def __repr__(self): + return f'Vector2d(x = {self.x}, y = {self.y})' + def __str__(self): + return f'{self.x}i + {self.y}j' + def __abs__(self): + return (self.x**2 + self.y**2)**0.5 + def __neg__(self): + return f'Vector2d({self.x}*-1, {self.y}*-1)' + def __add__(self,other): + return Vector2d((self.x + other.x), (self.y + other.y)) + def __eq__(self, other): + if (self.x, self.y) == (other.x, other.y): + return True + return False + def __sub__(self, other): + return Vector2d((self.x - other.x), (self.y - other.y)) + def angle(self): + tan = math.atan2((self.y), (self.x)) + return math.degrees(tan) \ No newline at end of file