From 124ec197c3a9f678bc90d168a51ca12ccd5539a5 Mon Sep 17 00:00:00 2001 From: 44004098 <121195860+44004098@users.noreply.github.com> Date: Tue, 21 Feb 2023 13:39:50 +0000 Subject: [PATCH 1/2] I defined a class with functions, repr, str, abs, neg, and add --- main.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 104be10..9f837b3 100644 --- a/main.py +++ b/main.py @@ -1,2 +1,20 @@ 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}) is True" + + def __str__(self): + return f"{self.x}i,{self.y}j" + + def __abs__(self): + hypotenuse = (self.x**2+self.y**2)**.5 + return hypotenuse + + 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 96a0cecff080a8c116af1a71997f13fb213ff1fd Mon Sep 17 00:00:00 2001 From: 44004098 <121195860+44004098@users.noreply.github.com> Date: Fri, 24 Feb 2023 19:41:51 +0000 Subject: [PATCH 2/2] Created a function to have an angle form and change it into degrees --- main.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 9f837b3..8ecb00b 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import math class Vector2d: def __init__(self, x,y): self.x = x @@ -17,4 +18,15 @@ 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 + return Vector2d((self.x + other.x),(self.y + other.y)) + + def __eq__(self,other): + if Vector2d((self.x == other.x),(self.y == other.y)): + return True + + def __sub__(self,other): + return self.x - other.x and self.y - other.y + + + def angle(self): + return math.degrees(math.atan2(self.y, self.x)) \ No newline at end of file