-
Notifications
You must be signed in to change notification settings - Fork 1
/
operations.py
68 lines (49 loc) · 1.51 KB
/
operations.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
60
61
62
63
64
65
66
67
68
def multMatriz(m1, m2):
matrizResult = [[0] * 4, [0] * 4, [0] * 4, [0] * 4]
for i in range(4):
for j in range(4):
soma = 0;
for k in range(4):
soma += m1[j][k] * m2[k][i];
matrizResult[j][i] = soma;
return matrizResult
def mult_vetor_matriz(v, m):
vetor_result = [0] * 4;
for j in range(4):
soma = 0;
for k in range(4):
soma += m[j][k] * v[k];
vetor_result[j] = soma;
if vetor_result[3] != 1:
for i in range(4):
vetor_result[i] = vetor_result[i] / vetor_result[3]
return vetor_result[0:3]
def product_vetorial(v1, v2):
result = [0] * 3
result[0] = v1[1] * v2[2] - v1[2] * v2[1]
result[1] = v1[2] * v2[0] - v1[0] * v2[2]
result[2] = v1[0] * v2[1] - v1[1] * v2[0]
return result
def mult_escalar_vetorial(v1, v2):
return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]
def division_vetorial(v1, f):
result = [0] * 3
result[0] = v1[0] / f
result[1] = v1[1] / f
result[2] = v1[2] / f
return result
def minus_vetorial(v1, v2):
result = [0] * 3
result[0] = v1[0] - v2[0]
result[1] = v1[1] - v2[1]
result[2] = v1[2] - v2[2]
return result
def modulo_vetorial(v):
result = (v[0] ** 2 + v[1] ** 2 + v[2] ** 2) ** 0.5
return result
def unitarizador(v):
mod = modulo_vetorial(v)
x = v[0] / mod
y = v[1] / mod
z = v[2] / mod
return [x, y, z]