-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmat_vec_tools.py
More file actions
38 lines (32 loc) · 1.61 KB
/
mat_vec_tools.py
File metadata and controls
38 lines (32 loc) · 1.61 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
#coding=utf8
########################################################################
### ###
### Created by Martin Genet, 2012-2016 ###
### ###
### University of California at San Francisco (UCSF), USA ###
### Swiss Federal Institute of Technology (ETH), Zurich, Switzerland ###
### École Polytechnique, Palaiseau, France ###
### ###
########################################################################
import numpy
import myVTKPythonLibrary as myVTK
########################################################################
def vec_col_to_mat_sym(vec):
if (numpy.size(vec,0) == 3):
return numpy.array([[vec[0], vec[2]],
[vec[2], vec[1]]])
elif (numpy.size(vec,0) == 6):
return numpy.array([[vec[0], vec[3], vec[4]],
[vec[3], vec[1], vec[5]],
[vec[4], vec[5], vec[2]]])
else:
print 'Wrong vector dimension in vec_col_to_mat_sym. Aborting.'
exit()
def mat_sym_to_vec_col(mat):
if (numpy.size(mat,0) == 2) and (numpy.size(mat,1) == 2):
return numpy.array([mat[0,0], mat[1,1], mat[0,1]])
elif (numpy.size(mat,0) == 3) and (numpy.size(mat,1) == 3):
return numpy.array([mat[0,0], mat[1,1], mat[2,2], mat[0,1], mat[0,2], mat[1,2]])
else:
print 'Wrong matrix dimension in mat_sym_to_vec_col. Aborting.'
exit()