diff --git a/SimPEG/Utils/coordutils.py b/SimPEG/Utils/coordutils.py index 0329495a..260e1a3b 100644 --- a/SimPEG/Utils/coordutils.py +++ b/SimPEG/Utils/coordutils.py @@ -1,4 +1,5 @@ import numpy as np +from SimPEG.Utils import mkvc def rotationMatrixFromNormals(v0,v1,tol=1e-20): """ @@ -56,4 +57,6 @@ def rotatePointsFromNormals(XYZ,n0,n1,x0=np.r_[0.,0.,0.]): assert XYZ.shape[1] == 3, "Grid XYZ should be 3 wide" assert len(x0) == 3, "x0 should have length 3" - return (XYZ - x0).dot(R.T) + x0 \ No newline at end of file + X0 = np.ones([XYZ.shape[0],1])*mkvc(x0) + + return (XYZ - X0).dot(R.T) + X0 # equivalent to (R*(XYZ - X0)).T + X0 \ No newline at end of file diff --git a/tests/utils/test_coordutils.py b/tests/utils/test_coordutils.py index dc036529..b17afcf7 100644 --- a/tests/utils/test_coordutils.py +++ b/tests/utils/test_coordutils.py @@ -23,7 +23,22 @@ class coorUtilsTest(unittest.TestCase): v1 = np.random.rand(3) v1*= 1./np.linalg.norm(v1) - self.assertTrue(np.linalg.norm(Utils.mkvc(Utils.coordutils.rotatePointsFromNormals(Utils.mkvc(v0,2).T,v0,v1))-v1) < tol) + v2 = Utils.mkvc(Utils.coordutils.rotatePointsFromNormals(Utils.mkvc(v0,2).T,v0,v1)) + + self.assertTrue(np.linalg.norm(v2-v1) < tol) + + def test_rotateMatrixFromNormals(self): + n0 = np.random.rand(3) + n0*= 1./np.linalg.norm(n0) + n1 = np.random.rand(3) + n1*= 1./np.linalg.norm(n1) + + scale = np.random.rand(100,1) + XYZ0 = scale * n0 + XYZ1 = scale * n1 + + XYZ2 = Utils.coordutils.rotatePointsFromNormals(XYZ0,n0,n1) + self.assertTrue(np.linalg.norm(Utils.mkvc(XYZ1) - Utils.mkvc(XYZ2))/np.linalg.norm(Utils.mkvc(XYZ1)) < tol) if __name__ == '__main__': unittest.main()