-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
44 lines (37 loc) · 1.23 KB
/
functions.py
File metadata and controls
44 lines (37 loc) · 1.23 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
class Perform(object):
def __init__(self, a):
self.x = a[0]
self.y = a[1]
self.z = a[2]
@staticmethod
def dot(a, b):
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
@staticmethod
def cross(a, b):
v1 = a[1] * b[2] - a[2] * b[1]
v2 = a[2] * b[0] - a[0] * b[2]
v3 = a[0] * b[1] - a[1] * b[0]
return (v1, v2, v3)
@staticmethod
def normalize1(a, b):
t1 = Perform.cross(a, b)
toRet = Perform.normalize(t1)
return toRet
# toRet = [t1[0], t1[1], t1[2]]
# currMag = sqrt(toRet[0] ** 2 + toRet[1] ** 2 + toRet[2] ** 2)
# if currMag == 0:
# return (0, 0, 0)
# toRet[0] = toRet[0] / float(currMag)
# toRet[1] = toRet[1] / float(currMag)
# toRet[2] = toRet[2] / float(currMag)
# return (toRet[0], toRet[1], toRet[2])
@staticmethod
def normalize(a):
toRet = [a[0], a[1], a[2]]
currMag = sqrt(a[0] ** 2 + a[1] ** 2 + a[2] ** 2)
if currMag == 0:
return (0, 0, 0)
toRet[0] /= float(currMag)
toRet[1] /= float(currMag)
toRet[2] /= float(currMag)
return (toRet[0], toRet[1], toRet[2])