-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix_functions.py
More file actions
48 lines (38 loc) · 852 Bytes
/
matrix_functions.py
File metadata and controls
48 lines (38 loc) · 852 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import math
import numpy as np
def translate(pos):
tx, ty, tz = pos
return np.array([
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[tx, ty, tz, 1]
])
def rotate_x(a):
return np.array([
[1, 0, 0, 0],
[0, math.cos(a), math.sin(a), 0],
[0, -math.sin(a), math.cos(a), 0],
[0, 0, 0, 1]
])
def rotate_y(a):
return np.array([
[math.cos(a), 0, -math.sin(a), 0],
[0, 1, 0, 0],
[math.sin(a), 0, math.cos(a), 0],
[0, 0, 0, 1]
])
def rotate_z(a):
return np.array([
[math.cos(a), math.sin(a), 0, 0],
[-math.sin(a), math.cos(a), 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]
])
def scale(n):
return np.array([
[n, 0, 0, 0],
[0, n, 0, 0],
[0, 0, n, 0],
[0, 0, 0, 1]
])