Exemple #1
0
    def test_rotation_around_axis_with_vector_input(self):
        angle = tf.constant([0.0, 0.5 * np.pi, -0.5 * np.pi, np.pi, -np.pi])
        x = rotation_matrix.from_rotation_around_x(angle)
        y = rotation_matrix.from_rotation_around_y(angle)
        z = rotation_matrix.from_rotation_around_z(angle)

        self.assertEqual(x.shape, (5, 3, 3))
        self.assertEqual(y.shape, (5, 3, 3))
        self.assertEqual(z.shape, (5, 3, 3))

        x = tf.matmul(x, rotation_matrix.from_rotation_around_x(-angle))
        y = tf.matmul(y, rotation_matrix.from_rotation_around_y(-angle))
        z = tf.matmul(z, rotation_matrix.from_rotation_around_z(-angle))

        expected = np.repeat(np.expand_dims(np.eye(3), axis=0), 5, axis=0)
        self.assertAllClose(x.numpy(), expected)
        self.assertAllClose(y.numpy(), expected)
        self.assertAllClose(z.numpy(), expected)
Exemple #2
0
    def test_rotation_around_axis_with_tensor_input(self):
        angle = tf.random.uniform(shape=(5, 1))
        x = rotation_matrix.from_rotation_around_x(angle)
        y = rotation_matrix.from_rotation_around_y(angle)
        z = rotation_matrix.from_rotation_around_z(angle)

        self.assertEqual(x.shape, (5, 3, 3))
        self.assertEqual(y.shape, (5, 3, 3))
        self.assertEqual(z.shape, (5, 3, 3))

        x = tf.matmul(x, rotation_matrix.from_rotation_around_x(-angle))
        y = tf.matmul(y, rotation_matrix.from_rotation_around_y(-angle))
        z = tf.matmul(z, rotation_matrix.from_rotation_around_z(-angle))

        expected = np.repeat(np.expand_dims(np.eye(3), axis=0), 5, axis=0)
        self.assertAllClose(x.numpy(), expected)
        self.assertAllClose(y.numpy(), expected)
        self.assertAllClose(z.numpy(), expected)
Exemple #3
0
    def test_rotation_around_axis_with_scalar_input(self):
        for rad in [0.0, 0.5 * np.pi, -0.5 * np.pi, np.pi, -np.pi]:
            angle = tf.constant(rad)
            x = rotation_matrix.from_rotation_around_x(angle)
            y = rotation_matrix.from_rotation_around_y(angle)
            z = rotation_matrix.from_rotation_around_z(angle)

            self.assertEqual(x.shape, (3, 3))
            self.assertEqual(y.shape, (3, 3))
            self.assertEqual(z.shape, (3, 3))

            x = tf.matmul(x, rotation_matrix.from_rotation_around_x(-angle))
            y = tf.matmul(y, rotation_matrix.from_rotation_around_y(-angle))
            z = tf.matmul(z, rotation_matrix.from_rotation_around_z(-angle))

            self.assertAllClose(x.numpy(), np.eye(3))
            self.assertAllClose(y.numpy(), np.eye(3))
            self.assertAllClose(z.numpy(), np.eye(3))
Exemple #4
0
    def test_from_euler(self):
        angles = tf.constant([[np.pi, 0.0, 0.0], [0.0, np.pi, 0.0],
                              [0.0, 0.0, np.pi], [np.pi, np.pi, np.pi],
                              [0.0, 0.0, 0.0]])
        rotations = rotation_matrix.from_euler(angles)

        x = rotation_matrix.from_rotation_around_x(tf.constant(np.pi))
        y = rotation_matrix.from_rotation_around_y(tf.constant(np.pi))
        z = rotation_matrix.from_rotation_around_z(tf.constant(np.pi))

        self.assertEqual(rotations.shape, (5, 3, 3))

        np_rotations = rotations.numpy()
        self.assertAllClose(np_rotations[0, Ellipsis], x.numpy())
        self.assertAllClose(np_rotations[1, Ellipsis], y.numpy())
        self.assertAllClose(np_rotations[2, Ellipsis], z.numpy())
        self.assertAllClose(np_rotations[3, Ellipsis],
                            z.numpy().dot(y.numpy()).dot(x.numpy()))
        self.assertAllClose(np_rotations[4, Ellipsis], np.eye(3))
Exemple #5
0
 def test_rotation_around_y_cos_sin(self):
     angle = tf.random.uniform(shape=(5, 1))
     y = rotation_matrix.from_rotation_around_y_cos_sin(cos=tf.cos(angle),
                                                        sin=tf.sin(angle))
     expected_y = rotation_matrix.from_rotation_around_y(angle)
     self.assertAllClose(y.numpy(), expected_y.numpy())