From 397446b07f22506b0340a9ae652136a8eebbc9b0 Mon Sep 17 00:00:00 2001 From: ChrisP324 <121184128+ChrisP324@users.noreply.github.com> Date: Thu, 16 Feb 2023 16:36:05 +0000 Subject: [PATCH 1/4] Created a 2d vector class --- main.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 104be10..14bb06a 100644 --- a/main.py +++ b/main.py @@ -1,2 +1,10 @@ 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 \ No newline at end of file From 8849ed25b50ceb875b53452c5d58a59bd63a8b7e Mon Sep 17 00:00:00 2001 From: ChrisP324 <121184128+ChrisP324@users.noreply.github.com> Date: Sun, 19 Feb 2023 01:16:02 +0000 Subject: [PATCH 2/4] 2/16 assignment --- main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 14bb06a..f09590f 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,14 @@ class Vector2d: def __init__(self,x, y): self.x = x - self.y = y: + 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 \ No newline at end of file + return ((self.x**2) + (self.y**2))**(0.5) + 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)) \ No newline at end of file From d278fe897b0b535add8d8e0c79bfc2c6f5082b27 Mon Sep 17 00:00:00 2001 From: ChrisP324 <121184128+ChrisP324@users.noreply.github.com> Date: Wed, 22 Feb 2023 02:23:23 +0000 Subject: [PATCH 3/4] revised 2/16 assigment --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index f09590f..d83c7fb 100644 --- a/main.py +++ b/main.py @@ -7,8 +7,8 @@ def __repr__(self): def __str__(self): return f'{self.x}i + {self.y}j' def __abs__(self): - return ((self.x**2) + (self.y**2))**(0.5) + return (self.x**2 + self.y**2)**0.5 def __neg__(self): - return Vector2d(self.x*-1, self.y*-1) + return f'Vector2d({self.x}*-1, {self.y}*-1)' def __add__(self,other): return Vector2d((self.x + other.x), (self.y + other.y)) \ No newline at end of file From ace0d6000e5158ce6e94f329b60271de6db0566d Mon Sep 17 00:00:00 2001 From: ChrisP324 <121184128+ChrisP324@users.noreply.github.com> Date: Fri, 24 Feb 2023 01:35:09 +0000 Subject: [PATCH 4/4] instructions of 2/22 and 23 done --- main.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index d83c7fb..6af30ca 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import math class Vector2d: def __init__(self,x, y): self.x = x @@ -11,4 +12,13 @@ def __abs__(self): 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)) \ No newline at end of file + 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