def tras_rot2(beam, p, theta): theta_grazing = np.pi / 2 - theta y = Vector(0., 1., 0.) y.rotation(-theta_grazing, 'x') x = Vector(1., 0., 0.) xp = x.vector_product(y) vrot = y.rodrigues_formula(xp, -theta_grazing) vrot.normalization() position = Vector(beam.x, beam.y, beam.z) velocity = Vector(beam.vx, beam.vy, beam.vz) position.rotation(-theta_grazing, 'x') velocity.rotation(-theta_grazing, 'x') #position = position.rodrigues_formula(xp, -theta_grazing) #velocity = velocity.rodrigues_formula(xp, -theta_grazing) velocity.normalization() beam.vx = velocity.x beam.vy = velocity.y beam.vz = velocity.z vector_point = Vector(0, p, 0) vector_point.rotation(-theta_grazing, "x") print(vector_point.info()) #vector_point = vector_point.rodrigues_formula(xp, -theta_grazing) vector_point.normalization() beam.x = position.x - vector_point.x * p beam.y = position.y - vector_point.y * p beam.z = position.z - vector_point.z * p
def test_rotation_1(self): print(">> test_rotation_1") theta=0*np.pi/180 v = Vector(0,1,0) v.rotation(-(90*np.pi/180-theta),"x") print(v.info()) assert_almost_equal ( v.x , 0.0 , 15) assert_almost_equal ( v.y , 0.0 , 15) assert_almost_equal ( v.z , -1.0 , 15)
def test_rotation_3(self): print(">> test_rotation_3") alpha=90*np.pi/180 v = Vector(0,1,0) v.rotation(alpha,"y") print(v.info()) assert_almost_equal ( v.x , 0.0 , 15) assert_almost_equal ( v.y , 1.0 , 15) assert_almost_equal ( v.z , 0.0 , 15)
def test_rotation_2(self): print(">> test_rotation_2") theta=45*np.pi/180 v = Vector(0,1,0) v.rotation(-(90*np.pi/180-theta),"x") print(v.info()) assert_almost_equal ( v.x , 0.0 , 15) assert_almost_equal ( v.y , 1/np.sqrt(2) , 15) assert_almost_equal ( v.z , -1/np.sqrt(2) , 15)
def test_rodrigues(self): print(">> test_rodrigues") theta=90*np.pi/180 axis=Vector(0,0,1) v=Vector(0,1,0) vrot=v.rodrigues_formula(axis,theta) print(v.info()) assert_almost_equal(vrot.x, -1.0, 15) assert_almost_equal(vrot.y, 0, 15) assert_almost_equal(vrot.z, 0, 15)
def test_normalizationvector(self): print(">> test_normalizationvector") x=1 y=1 z=1 v=Vector(x,y,z) v.normalization() print(v.info()) assert_almost_equal(v.x, 1/np.sqrt(3), 15) assert_almost_equal(v.y, 1/np.sqrt(3), 15) assert_almost_equal(v.z, 1/np.sqrt(3), 15)
def test_rotation_10_array(self): print(">> test_rotation_10_array") theta = 45*np.pi/180 alpha = 90*np.pi/180 x=np.zeros(10) y=np.ones(10) z=np.zeros(10) v=Vector(x,y,z) v.rotation(alpha,"y") v.rotation(-(90*np.pi/180 - theta), "x") print (v.info()) assert_almost_equal(v.x,np.zeros(10)) assert_almost_equal(v.y,1/np.sqrt(2) *np.ones(10)) assert_almost_equal(v.z,-1/np.sqrt(2)*np.ones(10))