-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransformation.py
More file actions
97 lines (60 loc) · 2.37 KB
/
Transformation.py
File metadata and controls
97 lines (60 loc) · 2.37 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'''
* Transformation.py
*
* Created on: 28.12.2018
* Author: Andrew Jason Bishop
*
* General description:
* xxx
'''
import numpy as np
class Transformation:
def __init__(self, _dimension):
self.identityMatrix = self.createIdentityMatrix( _dimension )
def createIdentityMatrix(self, _dimension):
identity = np.identity( _dimension, dtype=float )
return np.matrix( identity, copy=False )
def createTransforMatrix(self, _translation, _rotation, _scale):
pass
def createTranslationMatrix(self, _translation):
translationMatrix = np.matrix( self.identityMatrix )
self.addTranslationToGivenMatrix( _translation, translationMatrix )
return translationMatrix
def addTranslationToGivenMatrix(self, _translation, _matrix):
rowElementCount = _translation.shape[0]
asColumnVector = _translation.reshape(( rowElementCount ,1))
_matrix[ :rowElementCount, -1] = asColumnVector
def createTranslationMatrix(self, _translation):
translationMatrix = np.matrix( self.identityMatrix )
self.addTranslationToGivenMatrix( _translation, translationMatrix )
return translationMatrix
def addTranslationToGivenMatrix(self, _translation, _matrix):
rowElementCount = _translation.shape[0]
asColumnVector = _translation.reshape(( rowElementCount ,1))
_matrix[ :rowElementCount, -1] = asColumnVector
def rowVectorToColumnVector(self, _rowVector):
rowElementCount = _rowVector.shape[0]
asColumnVector = _rowVector.reshape((rowElementCount , 1))
return asColumnVector
if __name__ == '__main__':
myT = Transformation(4)
#print(myT.identityMatrix)
'''
a = np.matrix('1 2; 3 4')
b = np.identity(2, dtype=float)
m1 = np.asmatrix(b)
m2 = np.matrix( np.identity( 2, dtype=int ), copy=False )
# print("identity and asmatrix():\n", m1, type(m1))
# print("matrix(identity):\n", m2, type(m2))
# m = np.matrix( np.identity( 4, dtype=float ), copy=False )
m = myT.createIdentityMatrix()
print("identity matrix:\n", m)
t = np.array([0.2,0.2,0.2,1.0])
print(len(t))
print("translation vector:", t)
#tt = t.reshape((t.shape[0], 1))
#m[:, -1] = tt
myT.addTranslationToGivenMatrix( t, m )
print("updated to translation matrix:\n", m)
'''
''' END '''