-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinearTransformations.py
More file actions
40 lines (37 loc) · 1.28 KB
/
Copy pathLinearTransformations.py
File metadata and controls
40 lines (37 loc) · 1.28 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
import numpy as np
class Lineartransformations:
@staticmethod
def coordinate_stretching(par, ind):
"""
Generic function for coordinate stretching
"""
if ind > 2:
return ValueError("Index out of range, use 0, 1 or 2 for x, y or z")
mat = np.eye(4)
mat[3,3] = 0
mat[ind, ind] = par
return mat
@staticmethod
def coordinate_rotation(par, ind):
"""
Generic function for coordinate rotations.
Note that `par` must be given in radians
"""
if par > 2*np.pi:
return ValueError("Rotation angle `par` must be given in radians")
mat = np.zeros(4)
if ind == 0:
mat[0,0] = 1;
mat[1,1] = np.cos(par); mat[1,2] = -np.sin(par)
mat[2,1] = np.sin(par); mat[2,2] = np.cos(par)
elif ind == 1:
mat[1,1] = 1;
mat[0,0] = np.cos(par); mat[0,2] = np.sin(par)
mat[2,0] = -np.sin(par); mat[2,2] = np.cos(par)
elif ind == 2:
mat[2,2] = 1;
mat[0,0] = np.cos(par); mat[0,1] = -np.sin(par)
mat[1,0] = np.sin(par); mat[1,1] = np.cos(par)
else:
return ValueError("Index out of range, use 0, 1 or 2 for x, y or z")
return mat