This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_structures.py
59 lines (43 loc) · 1.72 KB
/
data_structures.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
from math import sin, cos, sqrt
class Vector():
def __init__(self, x, y, z):
if str in [type(x), type(y), type(z)]:
print('\n', x,y,z)
raise ValueError('Can only be numerical values')
self.x = x
self.y = y
self.z = z
self.texture = None
self.id = None
def __add__(self, other):
return Vector(self.x + other.x, self.y + other.y, self.z + other.z)
def __sub__(self, other):
return Vector(self.x - other.x, self.y - other.y, self.z - other.z)
def add(self, other):
self.x += other.x
self.y += other.y
self.z += other.z
def div(self, other):
self.x /= other
self.y /= other
self.z /= other
def mult(self, other):
self.x /= other
self.y /= other
self.z /= other
def get_xy(self):
return (int(self.x), int(self.y))
def get_xy_center(self, size):
return (int(self.x + size[0]/2), int(self.y + size[1]/2))
def rotate_x(self, a):
self.x = (1 * self.x) + (0 * self.y) + (0 * self.z)
self.y = (0 * self.x) + (cos(a) * self.y) + (-sin(a) * self.z)
self.z = (0 * self.x) + (sin(a) * self.y) + (cos(a) * self.z)
def rotate_y(self, a):
self.x = (cos(a) * self.x) + (0 * self.y) + (sin(a) * self.z)
self.y = (0 * self.x) + (1 * self.y) + (0 * self.z)
self.z = (-sin(a) * self.x) + (0 * self.y) + (cos(a) * self.z)
def rotate_z(self, a):
self.x = (cos(a) * self.x) + (-sin(a) * self.y) + (0 * self.z)
self.y = (sin(a) * self.x) + (cos(a) * self.y) + (0 * self.z)
self.z = (0 * self.x) + (0 * self.y) + (1 * self.z)