def test_align_2d_rotation_allow_mirror(): s_init = PointCloud(np.array([[-1., 1.], [1., 1.], [1., -1.], [-1., -1.]])) s_trg = PointCloud(np.array([[1., -1.], [1., 1.], [-1., 1.], [-1., -1.]])) # estimate the transform from source and target with mirroring allowed tr = AlignmentRotation(s_init, s_trg, allow_mirror=True) s_final = tr.apply(s_init) assert_allclose(s_final.points, s_trg.points, atol=1e-14) # estimate the transform from source and target with mirroring allowed tr = AlignmentRotation(s_init, s_trg, allow_mirror=False) s_final = tr.apply(s_init) assert_allclose(s_final.points, np.array([[-1., -1.], [-1., 1.], [1., 1.], [1., -1.]]), atol=1e-14)
def test_align_2d_rotation(): rotation_matrix = np.array([[0, 1], [-1, 0]]) rotation = Rotation(rotation_matrix) source = PointCloud(np.array([[0, 1], [1, 1], [-1, -5], [3, -5]])) target = rotation.apply(source) # estimate the transform from source and target estimate = AlignmentRotation(source, target) # check the estimates is correct assert_allclose(rotation.h_matrix, estimate.h_matrix, atol=1e-14)
def test_align_2d_rotation_set_h_matrix_raises_notimplemented_error(): rotation_matrix = np.array([[0, 1], [-1, 0]]) rotation = Rotation(rotation_matrix) source = PointCloud(np.array([[0, 1], [1, 1], [-1, -5], [3, -5]])) target = rotation.apply(source) # estimate the transform from source and source estimate = AlignmentRotation(source, source) # and set the target estimate.set_h_matrix(rotation.h_matrix)
def test_homog_compose_after_alignment_rotation(): homog = Homogeneous(np.array([[0, 1, 0], [1, 0, 0], [0, 0, 1]])) source = PointCloud(np.array([[0, 1], [1, 1], [-1, -5], [3, -5]])) r = AlignmentRotation(source, source) res = homog.compose_after(r) assert(type(res) == Homogeneous)
def rotation_alignment_angle_ccw(pts1, pts2): t = AlignmentRotation( Translation(-pts1.centre()).apply(pts1), Translation(-pts2.centre()).apply(pts2)) return 360 - math.degrees(t.axis_and_angle_of_rotation()[-1])