-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransformation.py
More file actions
52 lines (39 loc) · 1.13 KB
/
transformation.py
File metadata and controls
52 lines (39 loc) · 1.13 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
# transformation.py
import numpy as np
def rotate_x(points, angle):
"""Rotate points around the X-axis."""
cos_theta = np.cos(angle)
sin_theta = np.sin(angle)
rotation_matrix = np.array([
[1, 0, 0],
[0, cos_theta, -sin_theta],
[0, sin_theta, cos_theta]
])
return np.dot(points, rotation_matrix.T)
def rotate_y(points, angle):
"""Rotate points around the Y-axis."""
cos_theta = np.cos(angle)
sin_theta = np.sin(angle)
rotation_matrix = np.array([
[cos_theta, 0, sin_theta],
[0, 1, 0],
[-sin_theta, 0, cos_theta]
])
return np.dot(points, rotation_matrix.T)
def rotate_z(points, angle):
"""Rotate points around the Z-axis."""
cos_theta = np.cos(angle)
sin_theta = np.sin(angle)
rotation_matrix = np.array([
[cos_theta, -sin_theta, 0],
[sin_theta, cos_theta, 0],
[0, 0, 1]
])
return np.dot(points, rotation_matrix.T)
def scale(points, scale):
scale_matrix = np.array([
[scale, 0, 0],
[0, scale, 0],
[0, 0, scale]
])
return np.dot(points, scale_matrix.T)