示例#1
0
    def test_random(self):
        """Generation from various args"""
        s = (3, 4)
        np.random.seed(0)
        q = random.rand(s[0], s[1])
        self.assertTrue(q.shape == s + (4, ))
        self.assertTrue(np.allclose(norm(q), 1))

        q = random.rand()
        self.assertTrue(q.shape == (4, ))
示例#2
0
    def test_davenport(self):
        """Perform a rotation and ensure that we can recover it"""
        np.random.seed(0)

        for i in range(1, 12):
            num_points = 2**i

            points = np.random.rand(num_points, 3)
            rotation = random.rand(1)
            translation = np.random.rand(1, 3)

            transformed_points = rotate(rotation, points) + translation

            q, t = mapping.davenport(points, transformed_points)

            # In the case of just two points, the mapping is not unique,
            # so we don't check the mapping itself, just the result.
            if i > 1:
                self.assertTrue(
                    np.logical_or(
                        np.allclose(rotation, q),
                        np.allclose(rotation, -q),
                    ))
                self.assertTrue(np.allclose(translation, t))
            self.assertTrue(
                np.allclose(transformed_points,
                            rotate(q, points) + t))
示例#3
0
    def test_equivalent(self):
        """Perform a rotation and ensure that we can recover it"""
        # Test on an octahedron
        points = [[1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1],
                  [0, 0, -1]]

        # This is just a selected subset
        eq = [
            from_axis_angle([0, 0, 1], a)
            for a in [0, np.pi / 2, np.pi, 3 * np.pi / 2]
        ]

        np.random.seed(0)
        rotation = random.rand(1)
        translation = np.random.rand(1, 3)

        transformed_points = rotate(rotation, points) + translation

        q, t = mapping.procrustes(points,
                                  transformed_points,
                                  equivalent_quaternions=eq)

        # Sort the points in a deterministic manner for comparison
        recovered_points = rotate(q, points) + t
        ordered_recovered_points = recovered_points[np.argsort(
            recovered_points[:, 0])]
        ordered_transformed_points = transformed_points[np.argsort(
            transformed_points[:, 0])]

        self.assertTrue(
            np.allclose(ordered_recovered_points, ordered_transformed_points))