Skip to content
Snippets Groups Projects
Commit fc4d096f authored by Malte Nyhuis's avatar Malte Nyhuis
Browse files

more tests

more tests
parent 9912a340
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,11 @@ def calc_largedistant_idx(x_koords, y_koords):
return index_1, index_2
def symToMatrix(symTensor):
"""
tested translates symmetric tensor notation to complete matrix
:param symTensor:
:return:
"""
# xx,xy,xz,yy,yz,zz
Matrix = np.array([[symTensor[0], symTensor[1], symTensor[2]],
[symTensor[1], symTensor[3], symTensor[4]],
......@@ -39,15 +44,12 @@ def symToMatrix(symTensor):
return Matrix
def symToMatrixPVPoly(symTensor):
# xx,xy,xz,yy,yz,zz
Matrix = np.array([[symTensor[0], symTensor[3], symTensor[4]],
[symTensor[3], symTensor[1], symTensor[5]],
[symTensor[4], symTensor[5], symTensor[2]]])
return Matrix
def gradToRad(angle):
"""
tested method to translate from grad to rad
:param angle:
:return:
"""
return (angle / 180) * np.pi
......@@ -62,6 +64,7 @@ def Rx(xAngle):
[0, -np.sin(xAngle), np.cos(xAngle)]])
def Ry(yAngle):
"""
using radiant
......@@ -220,8 +223,6 @@ def minDists(vecs):
return mDist
def vecProjection(direction, vector):
unitDir = unitVec(direction)
return np.dot(vector, unitDir) * unitDir
......@@ -255,4 +256,3 @@ def lineseg_dist(p, a, b):
return np.hypot(h, np.linalg.norm(c))
import numpy as np
import pyvista as pv
from ntrfc.utils.math.vectorcalc import lineseg_dist
def test_absVec():
from ntrfc.utils.math.vectorcalc import vecAbs
......@@ -28,3 +30,51 @@ def test_randomUnitVec():
from ntrfc.utils.math.vectorcalc import randomUnitVec, vecAbs
rvec = randomUnitVec()
assert vecAbs(rvec)==1
def test_gradToRad():
from ntrfc.utils.math.vectorcalc import gradToRad
angle_grad = 180
angle_rad = gradToRad(angle_grad)
assert np.pi == angle_rad
def test_symToMatrix():
from ntrfc.utils.math.vectorcalc import symToMatrix
A = np.array([1,1,1,1,1,1])
R = symToMatrix(A)
assert all(np.equal(np.ones((3,3)),R).flatten())
def test_Rx():
from ntrfc.utils.math.vectorcalc import gradToRad, Rx
angle = 90
R = Rx(gradToRad(angle))
test_vec = np.array([0,0,1])
new_vec = np.dot(R,test_vec)
assert all(np.isclose(new_vec,np.array([0,1,0])))
def test_Ry():
from ntrfc.utils.math.vectorcalc import gradToRad, Ry
angle = 90
R = Ry(gradToRad(angle))
test_vec = np.array([1,0,0])
new_vec = np.dot(R,test_vec)
assert all(np.isclose(new_vec,np.array([0,0,1])))
def test_Rz():
from ntrfc.utils.math.vectorcalc import gradToRad, Rz
angle = 90
R = Rz(gradToRad(angle))
test_vec = np.array([0,1,0])
new_vec = np.dot(R,test_vec)
assert all(np.isclose(new_vec,np.array([1,0,0])))
def test_lineseg():
import pyvista as pv
line = pv.Line()
testpt = np.array([0,1,0])
pt_a, pt_b = line.points[0], line.points[-1]
assert line.length == lineseg_dist(testpt, pt_a, pt_b)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment