From a89ab2ce4aa2eb87954a0d24c840eff1a3d3a3c5 Mon Sep 17 00:00:00 2001 From: MaNyh <nyhuis@tfd.uni-hannover.de> Date: Fri, 10 Dec 2021 13:43:26 +0100 Subject: [PATCH] cleanup and test-implementations --- ntrfc/utils/math/vectorcalc.py | 12 +----------- tests/test_ntrfc_math.py | 32 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ntrfc/utils/math/vectorcalc.py b/ntrfc/utils/math/vectorcalc.py index 9ef1689d..36e64f40 100644 --- a/ntrfc/utils/math/vectorcalc.py +++ b/ntrfc/utils/math/vectorcalc.py @@ -103,16 +103,6 @@ def RotFromTwoVecs(vec1, vec2): return rotation_matrix -def radiusFromPt(pts, sigma): - pts = np.abs(pts) - if pts[1] > 0: - teta = np.arctan(pts[2] / pts[1]) - else: - teta = 0 - r = sigma[1] * sigma[2] / ((np.sin(teta) * sigma[2]) ** 2 + (np.cos(teta) * sigma[1]) ** 2) ** .5 - return r - - def vecAbs(vec): """ tested method to calculate the absolute value of a vector @@ -137,7 +127,7 @@ def posVec(vec): def findNearest(array, point): array = np.asarray(array) - idx = (np.abs(array - point)).argmin() + idx = np.array([vecAbs(i) for i in (np.abs(array - point))]).argmin() return idx diff --git a/tests/test_ntrfc_math.py b/tests/test_ntrfc_math.py index 55c980c2..5cf73a7d 100644 --- a/tests/test_ntrfc_math.py +++ b/tests/test_ntrfc_math.py @@ -100,10 +100,6 @@ def test_RotFromTwoVecs(): Rcontrol = Rz(np.pi/2) assert all(np.isclose(Rab,Rcontrol).flatten()) -def test_radiusFromPt(): - from ntrfc.utils.math.vectorcalc import radiusFromPt - a = radiusFromPt - def test_posVec(): import numpy as np @@ -114,23 +110,37 @@ def test_posVec(): b = posVec(a) blength = vecAbs(b) assert alength==blength - assert np.equal(-1*a,b) + assert all(np.isclose(-1*a,b).flatten()) def test_findNearest(): from ntrfc.utils.math.vectorcalc import findNearest - a = findNearest - + import pyvista as pv + import numpy as np + res = 100 + line = pv.Line(resolution=res) + point = np.array([0,0,0]) + near = findNearest(line.points,point) + assert near == int(res/2) def test_eulersFromRPG(): - from ntrfc.utils.math.vectorcalc import eulersFromRPG - a = eulersFromRPG + from ntrfc.utils.math.vectorcalc import eulersFromRPG, RotFromTwoVecs, vecAngle + import numpy as np + a = np.array([1, 0, 0]) + b = np.array([0, 1, 0]) + cangle = vecAngle(a,b) + R = RotFromTwoVecs(a,b) + + angle = eulersFromRPG(R) + assert angle[0]==cangle def test_randomOrthMat(): from ntrfc.utils.math.vectorcalc import randomOrthMat - a = randomOrthMat - + import numpy as np + o = randomOrthMat() + dot_o = np.dot(o,o.T) + assert all(np.isclose(dot_o,np.identity(3)).flatten()) def test_minDists(): from ntrfc.utils.math.vectorcalc import minDists -- GitLab