-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvector2.py
More file actions
32 lines (23 loc) · 777 Bytes
/
vector2.py
File metadata and controls
32 lines (23 loc) · 777 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
class vec2:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def dot(self, ov):
return self.x * ov.x + self.y * ov.y
def mag(self):
return (self.x**2 + self.y**2)**(0.5)
def normalized(self):
if self.mag():
return vec2(self.x/self.mag(), self.y/self.mag())
else:
return vec2()
def __repr__(self):
return "<" + str(self.x) + ", " + str(self.y) + ">"
def __add__(self, other):
return vec2(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return vec2(self.x - other.x, self.y - other.y)
def __mul__(self, s):
return vec2(self.x * s, self.y * s)
def __truediv__(self, s):
return vec2(self.x / s, self.y / s)