示例#1
0
 def test_rotate_y_torch_scalar(self):
     """
     Test rotation about Y axis. With a right hand coordinate system this
     should result in a vector pointing along the x-axis being rotated to
     point along the negative z axis.
     """
     angle = torch.tensor(90.0)
     t = RotateAxisAngle(angle=angle, axis="Y")
     # fmt: off
     matrix = torch.tensor(
         [[
             [0.0, 0.0, -1.0, 0.0],  # noqa: E241, E201
             [0.0, 1.0, 0.0, 0.0],  # noqa: E241, E201
             [1.0, 0.0, 0.0, 0.0],  # noqa: E241, E201
             [0.0, 0.0, 0.0, 1.0],  # noqa: E241, E201
         ]],
         dtype=torch.float32,
     )
     # fmt: on
     points = torch.tensor([1.0, 0.0, 0.0])[None, None, :]  # (1, 1, 3)
     transformed_points = t.transform_points(points)
     expected_points = torch.tensor([0.0, 0.0, -1.0])
     self.assertTrue(
         torch.allclose(transformed_points.squeeze(),
                        expected_points,
                        atol=1e-7))
     self.assertTrue(torch.allclose(t._matrix, matrix, atol=1e-7))
示例#2
0
 def test_rotate_z_python_scalar(self):
     t = RotateAxisAngle(angle=90, axis="Z")
     # fmt: off
     matrix = torch.tensor(
         [[
             [0.0, 1.0, 0.0, 0.0],  # noqa: E241, E201
             [-1.0, 0.0, 0.0, 0.0],  # noqa: E241, E201
             [0.0, 0.0, 1.0, 0.0],  # noqa: E241, E201
             [0.0, 0.0, 0.0, 1.0],  # noqa: E241, E201
         ]],
         dtype=torch.float32,
     )
     # fmt: on
     points = torch.tensor([1.0, 0.0, 0.0])[None, None, :]  # (1, 1, 3)
     transformed_points = t.transform_points(points)
     expected_points = torch.tensor([0.0, 1.0, 0.0])
     self.assertTrue(
         torch.allclose(transformed_points.squeeze(),
                        expected_points,
                        atol=1e-7))
     self.assertTrue(torch.allclose(t._matrix, matrix, atol=1e-7))