-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslations.py
35 lines (30 loc) · 985 Bytes
/
translations.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
import math as m
import numpy as np
class _RotationMatrix:
"""
_RotationMatrix namespace
"""
@staticmethod
def matrix(theta):
return (_RotationMatrix.rx(theta[0]) *
_RotationMatrix.ry(theta[1]) *
_RotationMatrix.rz(theta[2]))
@staticmethod
def rotate(vertices,theta):
R = _RotationMatrix.matrix(theta)
return R @ vertices
@staticmethod
def rx(theta):
return np.matrix([[1, 0, 0],
[0, m.cos(theta), -m.sin(theta)],
[0, m.sin(theta), m.cos(theta)]])
@staticmethod
def ry(theta):
return np.matrix([[m.cos(theta), 0, m.sin(theta)],
[0, 1, 0],
[-m.sin(theta), 0, m.cos(theta)]])
@staticmethod
def rz(theta):
return np.matrix([[m.cos(theta), -m.sin(theta), 0],
[m.sin(theta), m.cos(theta), 0],
[0, 0, 1]])