-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.py
More file actions
69 lines (60 loc) · 1.75 KB
/
Vector.py
File metadata and controls
69 lines (60 loc) · 1.75 KB
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
60
61
62
63
64
65
66
67
68
69
class Vector:
"""represente un vecteur 3d"""
def __init__(self, arg = (0, 0, 0)):
self.x = float(arg[0])
self.y = float(arg[1])
self.z = float(arg[2])
def set(self, val):
if isinstance(val, self.__class__):
self.x = val.x
self.y = val.y
self.z = val.z
else:
self.x = val[0]
self.y = val[1]
self.z = val[2]
return self;
def toString(self):
return "(" + str(self.x) + ", " + str(self.y) + ", " + str(self.z) + ")"
def __mul__(self, other):
if isinstance(other, self.__class__):
return Vector((self.x * other.x, self.y * other.y, self.z * other.z))
else:
return Vector((self.x * other, self.y * other, self.z * other))
def __rmul__(self, other):
if isinstance(other, self.__class__):
return Vector((self.x * other.x, self.y * other.y, self.z * other.z))
else:
return Vector((self.x * other, self.y * other, self.z * other))
def __imul__(self, other):
if isinstance(other, self.__class__):
self.x *= other.x
self.y *= other.y
self.z *= other.z
else:
self.x *= other
self.y *= other
self.z *= other
return self
def __add__(self, other):
if isinstance(other, self.__class__):
return Vector((self.x + other.x, self.y + other.y, self.z + other.z))
else:
return Vector((self.x + other, self.y + other, self.z + other))
def __radd__(self, other):
if isinstance(other, self.__class__):
return Vector((self.x + other.x, self.y + other.y, self.z + other.z))
else:
return Vector((self.x + other, self.y + other, self.z + other))
def __iadd__(self, other):
if isinstance(other, self.__class__):
self.x += other.x
self.y += other.y
self.z += other.z
else:
self.x += other
self.y += other
self.z += other
return self
def toTuple(self):
return (self.x, self.y, self.z)