From d33c8709af0ab6141dccd251df79a66c4796c979 Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Wed, 15 Feb 2023 16:26:46 +0000 Subject: [PATCH 01/17] Created a simple 2d vector class --- main.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..da0f710 --- /dev/null +++ b/main.py @@ -0,0 +1,13 @@ +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): + c = self.x ** 2 + self.y ** 2 + return c ** (1/2) + +test = Vector2d(3,4) \ No newline at end of file From 6b9d58037468ad95004c8eef49e350a71611626e Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Mon, 20 Feb 2023 13:48:59 +0000 Subject: [PATCH 02/17] Classwork for Vector2d class --- main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index da0f710..9ac6761 100644 --- a/main.py +++ b/main.py @@ -8,6 +8,14 @@ def __str__(self): return f"{self.x}i + {self.y}j" def __abs__(self): c = self.x ** 2 + self.y ** 2 - return c ** (1/2) + return c ** (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})" -test = Vector2d(3,4) \ No newline at end of file + +test = Vector2d(3,4) +test1 = Vector2d(1,-1) \ No newline at end of file From f4a823b1a13e0f171441050c4a861db6ee16222c Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Tue, 21 Feb 2023 16:25:45 +0000 Subject: [PATCH 03/17] Work from 2/21 --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 9ac6761..8ebff42 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ def __abs__(self): c = self.x ** 2 + self.y ** 2 return c ** (1/2) def __neg__(self): - return f"Vector2d(-{self.x}, -{self.y})" + return f"Vector2d({self.x * -1}, {self.y * -1})" def __add__(self, other): sum_x = self.x + other.x sum_y = self.y + other.y From a0f2f6e85d46fa5381442b7ab80e67cee357b7ea Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Fri, 24 Feb 2023 15:51:15 +0000 Subject: [PATCH 04/17] Work from 2/23 --- main.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 8ebff42..02331c4 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import math class Vector2d: def __init__(self, x, y): self.x = x @@ -14,8 +15,16 @@ def __neg__(self): def __add__(self, other): sum_x = self.x + other.x sum_y = self.y + other.y - return f"Vector2d({sum_x},{sum_y})" - + return f"Vector2d({sum_x},{sum_y})" + def __eq__(self, other): + if self.x == other.x and self.y == other.y: + return True + def __sub__(self, other): + dif_x = self.x - other.x + dif_y = self.y - other.y + return f"Vector2d({dif_x}, {dif_y})" + def angle(self): + return math.degrees(math.atan2(self.x, self.y)) test = Vector2d(3,4) test1 = Vector2d(1,-1) \ No newline at end of file From 1b8185883923d3e7a1c9e2915bbde8a90b9f5126 Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Fri, 24 Feb 2023 16:14:52 +0000 Subject: [PATCH 05/17] Completed Vector2d class work --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 02331c4..95c113e 100644 --- a/main.py +++ b/main.py @@ -24,7 +24,7 @@ def __sub__(self, other): dif_y = self.y - other.y return f"Vector2d({dif_x}, {dif_y})" def angle(self): - return math.degrees(math.atan2(self.x, self.y)) + return math.degrees(math.atan2(self.y, self.x)) test = Vector2d(3,4) -test1 = Vector2d(1,-1) \ No newline at end of file +test1 = Vector2d(1,1) \ No newline at end of file From a001f13a1e4c90f52cff4a77aa10db7752b7f364 Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Tue, 28 Feb 2023 17:14:52 +0000 Subject: [PATCH 06/17] Fixed Vector2d class --- main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 95c113e..a05be25 100644 --- a/main.py +++ b/main.py @@ -4,25 +4,25 @@ def __init__(self, x, y): self.x = x self.y = y def __repr__(self): - return f"Vector2d(x={self.x}, y={self.y})" + return Vector2d(self.x, self.y) def __str__(self): return f"{self.x}i + {self.y}j" def __abs__(self): c = self.x ** 2 + self.y ** 2 return c ** (1/2) def __neg__(self): - return f"Vector2d({self.x * -1}, {self.y * -1})" + return Vector2d(self.x * -1, self.y * -1) def __add__(self, other): sum_x = self.x + other.x sum_y = self.y + other.y - return f"Vector2d({sum_x},{sum_y})" + return Vector2d(sum_x,sum_y) def __eq__(self, other): if self.x == other.x and self.y == other.y: return True def __sub__(self, other): dif_x = self.x - other.x dif_y = self.y - other.y - return f"Vector2d({dif_x}, {dif_y})" + return Vector2d(dif_x, dif_y) def angle(self): return math.degrees(math.atan2(self.y, self.x)) From 5cacb088f0c44cb9ba5e4ad62671990ff69857c4 Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Wed, 1 Mar 2023 12:52:34 +0000 Subject: [PATCH 07/17] Completed flash card assignment from 2/28 --- flash_cards.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/flash_cards.py b/flash_cards.py index e69de29..a9f76a3 100644 --- a/flash_cards.py +++ b/flash_cards.py @@ -0,0 +1,9 @@ +def print_conversion(vector, str): + if str == "polar": + print(30 * "-") + print(f"Convert {vector.x}i + {vector.y}j to polar form") + print(30 * "-") + elif str == "rectangular": + print(30 * "-") + print(f"Convert <{abs(vector)}, {vector.angle()}> to rectangular form") + print(30 * "-") \ No newline at end of file From 442a0d6fd614f9de4c449af31b27457920790a31 Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Wed, 1 Mar 2023 16:26:13 +0000 Subject: [PATCH 08/17] Edited and completed print_conversion function assignment from 2/28 --- flash_cards.py | 11 ++++++----- vector2d.py | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/flash_cards.py b/flash_cards.py index a9f76a3..4156356 100644 --- a/flash_cards.py +++ b/flash_cards.py @@ -1,9 +1,10 @@ +from vector2d import Vector2d def print_conversion(vector, str): if str == "polar": - print(30 * "-") - print(f"Convert {vector.x}i + {vector.y}j to polar form") - print(30 * "-") + print(40 * "-") + print(f"Convert {vector.x}i + {vector.y}j to polar form") + print(40 * "-") elif str == "rectangular": - print(30 * "-") + print(40 * "-") print(f"Convert <{abs(vector)}, {vector.angle()}> to rectangular form") - print(30 * "-") \ No newline at end of file + print(40 * "-") \ No newline at end of file diff --git a/vector2d.py b/vector2d.py index 083c4ea..ccc7309 100644 --- a/vector2d.py +++ b/vector2d.py @@ -12,7 +12,7 @@ def __str__(self): return f"{self.x}i + {self.y}j" def __abs__(self): - return (self.x ** 2 + self.y ** 2) ** .5 + return round((self.x ** 2 + self.y ** 2) ** .5, 1) def __neg__(self): return Vector2d(-self.x, -self.y) @@ -27,4 +27,6 @@ def __sub__(self, other): return Vector2d(self.x - other.x, self.y - other.y) def angle(self): - return math.degrees(math.atan2(self.y, self.x)) + return round(math.degrees(math.atan2(self.y, self.x)), 1) + +test = Vector2d(3, 4) From f36361ec521b6cd5fe0bd56dd99147a334a317d8 Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Wed, 15 Feb 2023 16:26:46 +0000 Subject: [PATCH 09/17] Created a simple 2d vector class --- main.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..da0f710 --- /dev/null +++ b/main.py @@ -0,0 +1,13 @@ +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): + c = self.x ** 2 + self.y ** 2 + return c ** (1/2) + +test = Vector2d(3,4) \ No newline at end of file From 99f37d340f17c8834e7a199fff4969e64e6be13b Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Mon, 20 Feb 2023 13:48:59 +0000 Subject: [PATCH 10/17] Classwork for Vector2d class --- main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index da0f710..9ac6761 100644 --- a/main.py +++ b/main.py @@ -8,6 +8,14 @@ def __str__(self): return f"{self.x}i + {self.y}j" def __abs__(self): c = self.x ** 2 + self.y ** 2 - return c ** (1/2) + return c ** (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})" -test = Vector2d(3,4) \ No newline at end of file + +test = Vector2d(3,4) +test1 = Vector2d(1,-1) \ No newline at end of file From 93ec2f6bddea59028eb1f9e335e07b62e0553d9e Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Tue, 21 Feb 2023 16:25:45 +0000 Subject: [PATCH 11/17] Work from 2/21 --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 9ac6761..8ebff42 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ def __abs__(self): c = self.x ** 2 + self.y ** 2 return c ** (1/2) def __neg__(self): - return f"Vector2d(-{self.x}, -{self.y})" + return f"Vector2d({self.x * -1}, {self.y * -1})" def __add__(self, other): sum_x = self.x + other.x sum_y = self.y + other.y From c13209d22d40384d95eee6c6d92e6a53ea24e404 Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Fri, 24 Feb 2023 15:51:15 +0000 Subject: [PATCH 12/17] Work from 2/23 --- main.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 8ebff42..02331c4 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import math class Vector2d: def __init__(self, x, y): self.x = x @@ -14,8 +15,16 @@ def __neg__(self): def __add__(self, other): sum_x = self.x + other.x sum_y = self.y + other.y - return f"Vector2d({sum_x},{sum_y})" - + return f"Vector2d({sum_x},{sum_y})" + def __eq__(self, other): + if self.x == other.x and self.y == other.y: + return True + def __sub__(self, other): + dif_x = self.x - other.x + dif_y = self.y - other.y + return f"Vector2d({dif_x}, {dif_y})" + def angle(self): + return math.degrees(math.atan2(self.x, self.y)) test = Vector2d(3,4) test1 = Vector2d(1,-1) \ No newline at end of file From a0c8548fe67e0ad1698476439420d0a2e7fc469c Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Fri, 24 Feb 2023 16:14:52 +0000 Subject: [PATCH 13/17] Completed Vector2d class work --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 02331c4..95c113e 100644 --- a/main.py +++ b/main.py @@ -24,7 +24,7 @@ def __sub__(self, other): dif_y = self.y - other.y return f"Vector2d({dif_x}, {dif_y})" def angle(self): - return math.degrees(math.atan2(self.x, self.y)) + return math.degrees(math.atan2(self.y, self.x)) test = Vector2d(3,4) -test1 = Vector2d(1,-1) \ No newline at end of file +test1 = Vector2d(1,1) \ No newline at end of file From 5fbd0ed551481f1a22efd649248cbf4b66918e5f Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Tue, 28 Feb 2023 17:14:52 +0000 Subject: [PATCH 14/17] Fixed Vector2d class --- main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 95c113e..a05be25 100644 --- a/main.py +++ b/main.py @@ -4,25 +4,25 @@ def __init__(self, x, y): self.x = x self.y = y def __repr__(self): - return f"Vector2d(x={self.x}, y={self.y})" + return Vector2d(self.x, self.y) def __str__(self): return f"{self.x}i + {self.y}j" def __abs__(self): c = self.x ** 2 + self.y ** 2 return c ** (1/2) def __neg__(self): - return f"Vector2d({self.x * -1}, {self.y * -1})" + return Vector2d(self.x * -1, self.y * -1) def __add__(self, other): sum_x = self.x + other.x sum_y = self.y + other.y - return f"Vector2d({sum_x},{sum_y})" + return Vector2d(sum_x,sum_y) def __eq__(self, other): if self.x == other.x and self.y == other.y: return True def __sub__(self, other): dif_x = self.x - other.x dif_y = self.y - other.y - return f"Vector2d({dif_x}, {dif_y})" + return Vector2d(dif_x, dif_y) def angle(self): return math.degrees(math.atan2(self.y, self.x)) From 4a2a27facdeb4b7310278a7194365013d4050e47 Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Wed, 1 Mar 2023 12:52:34 +0000 Subject: [PATCH 15/17] Completed flash card assignment from 2/28 --- flash_cards.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/flash_cards.py b/flash_cards.py index e69de29..a9f76a3 100644 --- a/flash_cards.py +++ b/flash_cards.py @@ -0,0 +1,9 @@ +def print_conversion(vector, str): + if str == "polar": + print(30 * "-") + print(f"Convert {vector.x}i + {vector.y}j to polar form") + print(30 * "-") + elif str == "rectangular": + print(30 * "-") + print(f"Convert <{abs(vector)}, {vector.angle()}> to rectangular form") + print(30 * "-") \ No newline at end of file From 32d8aeb6a37c19e77d8fa12b5b26316a6e62815f Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Wed, 1 Mar 2023 16:26:13 +0000 Subject: [PATCH 16/17] Edited and completed print_conversion function assignment from 2/28 --- flash_cards.py | 11 ++++++----- vector2d.py | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/flash_cards.py b/flash_cards.py index a9f76a3..4156356 100644 --- a/flash_cards.py +++ b/flash_cards.py @@ -1,9 +1,10 @@ +from vector2d import Vector2d def print_conversion(vector, str): if str == "polar": - print(30 * "-") - print(f"Convert {vector.x}i + {vector.y}j to polar form") - print(30 * "-") + print(40 * "-") + print(f"Convert {vector.x}i + {vector.y}j to polar form") + print(40 * "-") elif str == "rectangular": - print(30 * "-") + print(40 * "-") print(f"Convert <{abs(vector)}, {vector.angle()}> to rectangular form") - print(30 * "-") \ No newline at end of file + print(40 * "-") \ No newline at end of file diff --git a/vector2d.py b/vector2d.py index 083c4ea..ccc7309 100644 --- a/vector2d.py +++ b/vector2d.py @@ -12,7 +12,7 @@ def __str__(self): return f"{self.x}i + {self.y}j" def __abs__(self): - return (self.x ** 2 + self.y ** 2) ** .5 + return round((self.x ** 2 + self.y ** 2) ** .5, 1) def __neg__(self): return Vector2d(-self.x, -self.y) @@ -27,4 +27,6 @@ def __sub__(self, other): return Vector2d(self.x - other.x, self.y - other.y) def angle(self): - return math.degrees(math.atan2(self.y, self.x)) + return round(math.degrees(math.atan2(self.y, self.x)), 1) + +test = Vector2d(3, 4) From 87dd3d3e5eddf3ec97e082aa0069de43aca413b7 Mon Sep 17 00:00:00 2001 From: WilliamV1211 <121183887+WilliamV1211@users.noreply.github.com> Date: Mon, 6 Mar 2023 12:49:25 +0000 Subject: [PATCH 17/17] Completed work from 3/1 and added 2 functions to flash_cards.py --- flash_cards.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/flash_cards.py b/flash_cards.py index 4156356..dd3d77f 100644 --- a/flash_cards.py +++ b/flash_cards.py @@ -1,3 +1,4 @@ +import random from vector2d import Vector2d def print_conversion(vector, str): if str == "polar": @@ -7,4 +8,15 @@ def print_conversion(vector, str): elif str == "rectangular": print(40 * "-") print(f"Convert <{abs(vector)}, {vector.angle()}> to rectangular form") - print(40 * "-") \ No newline at end of file + print(40 * "-") + +def generate_vector(): + random_x = random.randint(-20,21) + random_y = random.randint(-20,21) + return Vector2d(random_x, random_y) + +def print_conversion_solution(vector, str): + if str == "polar": + print(f"<{abs(vector)}, {vector.angle()}>") + elif str == "rectangular": + print(f"{vector.x}i + {vector.y}j") \ No newline at end of file