forked from NBHS-STEM/vector2d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector2d.py
More file actions
30 lines (21 loc) · 736 Bytes
/
Copy pathvector2d.py
File metadata and controls
30 lines (21 loc) · 736 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
import math
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):
return (self.x ** 2 + self.y ** 2) ** .5
def __neg__(self):
return Vector2d(-self.x, -self.y)
def __add__(self, other):
return Vector2d(self.x + other.x, self.y + other.y)
def __eq__(self, other):
return (self.x, self.y) == (other.x, other.y)
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))