diff --git a/ntrfc/utils/math/vectorcalc.py b/ntrfc/utils/math/vectorcalc.py index 9ef1689d72806165d259b7466119511b5e83c29e..36e64f4049771fd82de86144d6057695e52e0d3d 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 55c980c2eb37490d929be29ff0ff09e30211831f..5cf73a7d8f8a2ee0b2850b414633edf51ae49a20 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