make sure subtraction of x0 is a matrix with length of number of points, add test for giving an array XYZ

This commit is contained in:
Lindsey Heagy
2015-11-05 16:22:31 -08:00
parent 96b855d71d
commit 7b0bea4e1d
2 changed files with 20 additions and 2 deletions
+4 -1
View File
@@ -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
X0 = np.ones([XYZ.shape[0],1])*mkvc(x0)
return (XYZ - X0).dot(R.T) + X0 # equivalent to (R*(XYZ - X0)).T + X0
+16 -1
View File
@@ -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()