-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.py
61 lines (43 loc) · 1.4 KB
/
vector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# @Author: Marcel Maluta
# @Date: 2022-05-07T10:43:43+02:00
# @Email: [email protected]
# @Last modified by: Marcel Maluta
# @Last modified time: 2022-05-07T14:59:29+02:00
import math
class Vector2D(object):
x: int
y: int
def __init__(self, x:int=0, y:int=0):
self.x = x
self.y = y
def add(self, x:int, y:int):
self.x += x
self.y += y
def add_vector(self, vector:object):
self.x += vector.x
self.y += vector.y
def set(self, x:int, y:int):
self.x = x
self.y = y
def getX(self) -> int:
return self.x
def getY(self) -> int:
return self.y
def getPoint(self) -> tuple:
tuple = (self.x, self.y)
return tuple
def getLength(self) -> float:
sum = math.sqrt(math.pow(self.x, 2) + math.pow(self.y, 2))
return sum
def printVector(self):
print(f"({self.x}, {self.y})")
def __add__(self, other: object) -> object:
return Vector2D(self.x + other.x, self.y + other.y)
def __sub__(self, other: object) -> object:
return Vector2D(self.x - other.x, self.y - other.y)
def __mul__(self, other: int) -> object:
return Vector2D(self.x * other, self.y * other)
def __str__(self):
return f"({self.x}, {self.y})"
def dot(self, other:object) -> int:
return self.x * other.x + self.y * other.y