-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.py
More file actions
41 lines (30 loc) · 951 Bytes
/
Vector.py
File metadata and controls
41 lines (30 loc) · 951 Bytes
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
#############################################################
## IMPORT
from math import sqrt
#############################################################
## VECTOR
class Vector():
def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return f"[{self.x}, {self.y}]"
def __repr__(self):
return self.__str__()
def scalar_m(self, sca):
return Vector(sca*self.x, sca*self.y)
def norm(self):
ab = abs(self)
return Vector(self.x/ab, self.y/ab)
def __abs__(self):
return sqrt(self.x**2 + self.y**2)
def __add__(self, other):
x = self.x + other.x
y = self.y + other.y
return Vector(x, y)
def __sub__(self, other):
x = self.x - other.x
y = self.y - other.y
return Vector(x, y)
def __mul__(self, other):
return self.x*other.x+self.y*other.y