Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
import math
class Vector2d:
pass
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))**(1/2)
def __neg__(self):
return 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} == {other.x}) == True:
if ({self.y} == {other.y}) == True:
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)