-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.py
More file actions
35 lines (28 loc) · 954 Bytes
/
transform.py
File metadata and controls
35 lines (28 loc) · 954 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
from math import *
import numpy as np
from matrix import matrix
class transform(matrix):
def __init__(self):
super().__init__(np.identity(4))
def identity(self):
return self
def translate(self, Tx=0.0, Ty=0.0, Tz=0.0):
self.set(0, 3, Tx)
self.set(1, 3, Ty)
self.set(2, 3, Tz)
return self
def scale(self, Sx=1.0, Sy=1.0, Sz=1.0):
self.set(0, 0, Sx)
self.set(1, 1, Sy)
self.set(2, 2, Sz)
return self
def rotate(self, A=matrix(np.ones((3, 1))), angle=0.0):
A = A.normalize()
V = matrix(np.zeros((4, 4)))
V.set(0, 1, -A.get(2, 0))
V.set(0, 2, A.get(1, 0))
V.set(1, 0, A.get(2, 0))
V.set(1, 2, -A.get(0, 0))
V.set(2, 0, -A.get(1, 0))
V.set(2, 1, A.get(0, 0))
return self + V.scalarMultiply(sin(angle)) + (V * V).scalarMultiply(1.0 - cos(angle))