Ejemplo n.º 1
0
 def test_Rz30(self):
     """ right handed, 30 degrees around z """
     o = gv_general.rotation_axis([0, 0, 1], 30)
     c30 = math.sqrt(3) / 2.  # cos(30)
     s30 = 0.5  # sin(30)
     r = np.transpose(np.array([[c30, s30, 0], [-s30, c30, 0], [0, 0, 1]]))
     e = array_diff(o.to_matrix(), r)
     self.assertAlmostEqual(e, 0.0, 6)
Ejemplo n.º 2
0
 def test_rotate_vectors1(self):
     """ rotate a single vector """
     o = gv_general.rotation_axis([0, 0, 1], 180)
     vecs = np.transpose(np.array([[1, 1, 0]]))
     res = np.transpose(np.array([[-1, -1, 0]]))
     self.assertAlmostEqual(array_diff(o.rotate_vectors(vecs), res), 0, 6)
     self.assertAlmostEqual(array_diff(o.rotate_vectors(vecs, [180]), res),
                            0, 6)
     r1 = o.rotate_vectors(vecs, [181])
     self.assertNotAlmostEqual(array_diff(r1, res), 0, 6)
Ejemplo n.º 3
0
 def test_rotate_vectors_a(self):
     """rotate again 3x3, with different angles"""
     o = gv_general.rotation_axis([0, 0, 1], 90)
     vecs = np.transpose(np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]))
     res = np.transpose(np.array([[0, 0, 1], [-1, 0, 0], [0, 1, 0]]))
     self.assertAlmostEqual(array_diff(o.rotate_vectors(vecs), res), 0, 6)
     r2 = o.rotate_vectors(vecs, [90, 90, 90])
     #print "\n",np.array_str(r2, suppress_small=1)
     #print res
     self.assertAlmostEqual(array_diff(r2, res), 0, 6)
     self.assertNotAlmostEqual(
         array_diff(o.rotate_vectors(vecs, [90, 91, 90]), res), 0, 6)
Ejemplo n.º 4
0
 def test_rotate_vectors(self):
     """rotate 3x3 vectors, angs or not"""
     o = gv_general.rotation_axis([0, 0, 1], 90.0)
     vecs = np.transpose(
         np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 0, 0]], np.float))
     res = np.transpose(
         np.array([[0, 0, 1], [-1, 0, 0], [0, 1, 0], [0, 1, 0]], np.float))
     m1, m2 = o.rotate_vectors(vecs), res
     self.assertEqual(m1.shape, m2.shape)
     err = "\n\n" + str(m1.astype(np.int)) + " != \n\n" + str(m2)
     self.assertAlmostEqual(array_diff(m1, m2), 0, 6, err)
     angs = np.array([90.] * 4, np.float)
     m3, m4 = o.rotate_vectors(vecs, angs), res
     err = "\n\n" + str(m3.astype(np.int)) + " != \n\n" + str(m4)
     self.assertAlmostEqual(array_diff(m3, m4), 0, 6, err)
Ejemplo n.º 5
0
 def test_rotate_vectors2(self):
     """ rotate more vectors """
     o = gv_general.rotation_axis([0, 0, 1], 180)
     vecs = np.transpose(
         np.array(
             [
                 [0, 0, 1],  #1
                 [0, 1, 0],  #2
                 [0, 1, 1],  #3
                 [1, 1, 0],  #4
                 [-1, 1, 0],  #5
                 [1, 0, 0],  #6
                 [0, 1, 1]
             ],
             np.float))
     res = np.transpose(
         np.array(
             [
                 [0, 0, 1],  #1
                 [0, -1, 0],  #2
                 [0, -1, 1],  #3
                 [-1, -1, 0],  #4
                 [1, -1, 0],  #5
                 [-1, 0, 0],  #6
                 [0, -1, 1]
             ],
             np.float))
     r1 = o.rotate_vectors(vecs)
     #print np.array_str(r1,precision=1,suppress_small=1)
     #print res
     #print np.array_str(r1-res,precision=1,suppress_small=0)
     self.assertAlmostEqual(array_diff(r1, res), 0, 6)
     self.assertAlmostEqual(
         array_diff(
             o.rotate_vectors(
                 vecs,
                 #1  2    3   4   5   6   7
                 [180, 180, 180, 180, 180, 180, 180]),
             res),
         0,
         5)
Ejemplo n.º 6
0
def testaxisang():
    v = np.array([11.,12.,13.],np.float)
    cv = v.copy()
    axis = np.array([np.sqrt(1./3),-np.sqrt(1./3),np.sqrt(1./3)],np.float)

    for i in range(len(omega)):
        a = gv_general.rotation_axis(axis, angle=omega[i])
        rv = a.rotate_vectors( v )
        wripaca.rotate_vector_axis_angle(
                axis,
                omega[i]*np.pi/180,
                v,
                cv)
        co=np.cos(omega[i]*np.pi/180)
        so=np.sin(omega[i]*np.pi/180)
        M = np.array([[co,so,0],[-so,co,0],[0,0,1]])
        sv= np.dot(M,v)
        if 0:
            print "Omega =",omega[i]
            print "py    ",rv
            print "simple",sv
            print "affine",cv
        assert ((cv-rv)**2).sum()<1e-10,"badness in axis angle"
    print "AxisAngleOK"
Ejemplo n.º 7
0
 def test_Rz0(self):
     """ zero rotation around z give identity"""
     o = gv_general.rotation_axis([0, 0, 1], 0)
     self.assertAlmostEqual(
         array_diff(o.to_matrix(), np.identity(3, np.float)), 0.0, 6)