-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.py
More file actions
40 lines (28 loc) · 947 Bytes
/
vector.py
File metadata and controls
40 lines (28 loc) · 947 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
class Vector:
def __init__(self, x=0, z=0) -> None:
self.x = x
self.z = z
def to_list(self):
return [self.x, self.z]
def __iadd__(self, other):
self.x += other.x
self.z += other.z
return self
def __imul__(self, other):
self.x *= other
self.z *= other
return self
def __mul__(self, other):
return Vector(self.x*other, self.z*other)
def __add__(self, other):
return Vector(self.x + other.x, self.z + other.z)
def __sub__(self, other):
return Vector(self.x - other.x, self.z - other.z)
def __repr__(self) -> str:
return f'({self.x :.2f}, {self.z :.2f})'
def under_ground(self):
return self.z <= 0.
def copy(self):
return Vector(self.x, self.z)
def dist(self, other):
return ((self.x - other.x)**2 + (self.z - other.z)**2)**0.5