From 3667ab3ed4022095d2ce30a5aa500528183f97d1 Mon Sep 17 00:00:00 2001 From: aydengzzz <121195820+aydengzzz@users.noreply.github.com> Date: Wed, 15 Feb 2023 19:55:49 +0000 Subject: [PATCH 1/2] Start of Vector2d class --- main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 104be10..85adc43 100644 --- a/main.py +++ b/main.py @@ -1,2 +1,10 @@ -class Vector2d: - pass \ No newline at end of file +class Vector2d: + 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) \ No newline at end of file From 7a5a8cd793b3a85e0d6508c7a7bae146a8d8f5d0 Mon Sep 17 00:00:00 2001 From: aydengzzz <121195820+aydengzzz@users.noreply.github.com> Date: Fri, 24 Feb 2023 19:41:54 +0000 Subject: [PATCH 2/2] Vector2d class update --- main.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 85adc43..6b1342c 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import math class Vector2d: def __init__(self,x ,y): self.x = x @@ -7,4 +8,25 @@ def __repr__(self): def __str__(self): return f"{self.x}i + {self.y}j" def __abs__(self): - return ((self.x**2)+(self.y**2))**(1/2) \ No newline at end of file + return ((self.x**2)+(self.y**2))**(1/2) + def __neg__(self): + return f"Vector2d(-{self.x},-{self.y})" + def __add__(self,other): + sum_x = self.x + other.x + sum_y = self.y + other.y + return f"Vector2d({sum_x},{sum_y})" + def __eq__(self,other): + return (self.x ,self.y)== (other.x,other.y) + def __sub__(self,other): + diff_x = self.x - self.x + diff_y = self.y - self.y + return f"Vector2d({diff_x},{diff_y})" + def angle(self): + tan = math.atan2(self.x),(self.y) + return math.degrees(tan) + + + + + + \ No newline at end of file