def test_rodrigues_to_dcm(): RES = np.array([[0.50017235, -0.80049871, 0.33019604], [0.80739289, 0.56894174, 0.15627544], [-0.3129606, 0.18843328, 0.9308859]]) R = gtr._rodrigues_to_dcm(TEST_UVEC, TEST_ANGLE) # assess rotation matrix properties: # detR = +=1 nt.assert_almost_equal(np.linalg.det(R), 1.) # R.T = R^-1 nt.assert_true(np.allclose(np.linalg.inv(R), R.transpose())) # check against calculated matrix nt.assert_true(np.allclose(R, RES)) # check if opposite sign generates inverse Rinv = gtr._rodrigues_to_dcm(TEST_UVEC, -TEST_ANGLE) nt.assert_true(np.allclose(np.dot(Rinv, R), np.identity(3))) # check basic rotations with a range of angles for angle in np.linspace(0., 2. * np.pi, 10): Rx = gtr._rodrigues_to_dcm(np.array([1., 0., 0.]), angle) Ry = gtr._rodrigues_to_dcm(np.array([0., 1., 0.]), angle) Rz = gtr._rodrigues_to_dcm(np.array([0., 0., 1.]), angle) nt.assert_true(np.allclose(Rx, _Rx(angle))) nt.assert_true(np.allclose(Ry, _Ry(angle))) nt.assert_true(np.allclose(Rz, _Rz(angle)))
def test_rodrigues_to_dcm(): RES = np.array([[0.50017235, -0.80049871, 0.33019604], [0.80739289, 0.56894174, 0.15627544], [-0.3129606, 0.18843328, 0.9308859]]) R = gtr._rodrigues_to_dcm(TEST_UVEC, TEST_ANGLE) # assess rotation matrix properties: # detR = +=1 assert_almost_equal(np.linalg.det(R), 1.) # R.T = R^-1 assert np.allclose(np.linalg.inv(R), R.transpose()) # check against calculated matrix assert np.allclose(R, RES) # check if opposite sign generates inverse Rinv = gtr._rodrigues_to_dcm(TEST_UVEC, -TEST_ANGLE) assert np.allclose(np.dot(Rinv, R), np.identity(3)) # check basic rotations with a range of angles for angle in np.linspace(0., 2. * np.pi, 10): Rx = gtr._rodrigues_to_dcm(np.array([1., 0., 0.]), angle) Ry = gtr._rodrigues_to_dcm(np.array([0., 1., 0.]), angle) Rz = gtr._rodrigues_to_dcm(np.array([0., 0., 1.]), angle) assert np.allclose(Rx, _Rx(angle)) assert np.allclose(Ry, _Ry(angle)) assert np.allclose(Rz, _Rz(angle))
def test_pivot_rotate_point(): point = [1, 2, 3] new_orig = np.array([10. , 45., 50.]) t = gtr.Translation(new_orig) t_inv = gtr.Translation(new_orig * -1) R = gtr._rodrigues_to_dcm(TEST_UVEC, np.pi) # change origin, rotate 180 p1 = gtr.PivotRotation(R, new_orig)(point) # do the steps manually p2 = t_inv(point) p2 = gtr.Rotation(R)(p2) p2 = t(p2) nt.assert_equal(p1.tolist(), p2.tolist())
def test_pivot_rotate_point(): point = [1, 2, 3] new_orig = np.array([10., 45., 50.]) t = gtr.Translation(new_orig) t_inv = gtr.Translation(new_orig * -1) R = gtr._rodrigues_to_dcm(TEST_UVEC, np.pi) # change origin, rotate 180 p1 = gtr.PivotRotation(R, new_orig)(point) # do the steps manually p2 = t_inv(point) p2 = gtr.Rotation(R)(p2) p2 = t(p2) assert p1.tolist() == p2.tolist()
def test_pivot_rotate_points(): points = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) new_orig = np.array([10., 45., 50.]) t = gtr.Translation(new_orig) t_inv = gtr.Translation(new_orig * -1) R = gtr._rodrigues_to_dcm(TEST_UVEC, np.pi) # change origin, rotate 180 p1 = gtr.PivotRotation(R, new_orig)(points) # do the steps manually p2 = t_inv(points) p2 = gtr.Rotation(R)(p2) p2 = t(p2) nt.assert_true(np.all(p1 == p2))
def test_pivot_rotate_points(): points = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) new_orig = np.array([10. , 45., 50.]) t = gtr.Translation(new_orig) t_inv = gtr.Translation(new_orig * -1) R = gtr._rodrigues_to_dcm(TEST_UVEC, np.pi) # change origin, rotate 180 p1 = gtr.PivotRotation(R, new_orig)(points) # do the steps manually p2 = t_inv(points) p2 = gtr.Rotation(R)(p2) p2 = t(p2) nt.assert_true(np.all(p1 == p2))
def test_rotate_neurite_h5(): nrn_a = load_neuron(H5_NRN_PATH) nrt_a = nrn_a.neurites[0] nrt_b = gtr.rotate(nrt_a, [0,0,1], math.pi/2.0) rot = gtr._rodrigues_to_dcm([0,0,1], math.pi/2.0) _check_fst_neurite_rotate(nrt_a, nrt_b, rot)
def test_rotate_neuron_swc(): nrn_a = load_neuron(SWC_NRN_PATH) nrn_b = gtr.rotate(nrn_a, [0,0,1], math.pi/2.0) rot = gtr._rodrigues_to_dcm([0,0,1], math.pi/2.0) _check_fst_nrn_rotate(nrn_a, nrn_b, rot)
def test_rotate_neuron_h5(): nrn_a = load_neuron(H5_NRN_PATH) nrn_b = gtr.rotate(nrn_a, [0, 0, 1], math.pi/2.0) rot = gtr._rodrigues_to_dcm([0, 0, 1], math.pi/2.0) _check_fst_nrn_rotate(nrn_a, nrn_b, rot)
def test_rotate_neurite_swc(): nrn_a = load_neuron(SWC_NRN_PATH) nrt_a = nrn_a.neurites[0] nrt_b = gtr.rotate(nrt_a, [0,0,1], math.pi/2.0) rot = gtr._rodrigues_to_dcm([0,0,1], math.pi/2.0) _check_fst_neurite_rotate(nrt_a, nrt_b, rot)