-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeometric_transf.py
63 lines (49 loc) · 1.86 KB
/
geometric_transf.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
# File containg functions that return all sort of transformation matrixes. Created to abstract the math in other codes.
import math
import numpy as np
def get_mat_translation(t_x, t_y, t_z):
'''
Returns a translation matrix according to the translation variables received.
'''
return np.array([[1.0, 0.0, 0.0, t_x],
[0.0, 1.0, 0.0, t_y],
[0.0, 0.0, 1.0, t_z],
[0.0, 0.0, 0.0, 1.0]], np.float32)
def get_mat_scale(s_x, s_y, s_z):
'''
Returns a scale matrix according to the scale variables received.
'''
return np.array([[s_x, 0.0, 0.0, 0.0],
[0.0, s_y, 0.0, 0.0],
[0.0, 0.0, s_z, 0.0],
[0.0, 0.0, 0.0, 1.0]], np.float32)
def get_mat_rotation_x(angle):
'''
Returns a X axis rotation matrix according to the angle variable received.
'''
sin = math.sin(angle)
cos = math.cos(angle)
return np.array([[1.0, 0.0, 0.0, 0.0],
[0.0, cos, -sin, 0.0],
[0.0, sin, cos, 0.0],
[0.0, 0.0, 0.0, 1.0]], np.float32)
def get_mat_rotation_y(angle):
'''
Returns a Y axis rotation matrix according to the angle variable received.
'''
sin = math.sin(angle)
cos = math.cos(angle)
return np.array([[ cos, 0.0, sin, 0.0],
[ 0.0, 1.0, 0.0, 0.0],
[-sin, 0.0, cos, 0.0],
[ 0.0, 0.0, 0.0, 1.0]], np.float32)
def get_mat_rotation_z(angle):
'''
Returns a Z axis rotation matrix according to the angle variable received.
'''
sin = math.sin(angle)
cos = math.cos(angle)
return np.array([[cos, -sin, 0.0, 0.0],
[sin, cos, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0]], np.float32)