Example #1
0
 def test_chain_rotation(self):
     numpy.testing.assert_array_equal(
         numpy.round(
             numpy.matmul(
                 numpy.matmul(
                     rotation_matrix_xyz(*numpy.deg2rad([0, 90, 0])),
                     rotation_matrix_xyz(*numpy.deg2rad([0, 90, 0])),
                 ),
                 (1, 1, 1, 1),
             )[:3],
             1,
         ),
         (-1, 1, -1),
     )
Example #2
0
    def test_decompose(self):
        rotation_ = (1, 1.5, 3)
        m = rotation_matrix_xyz(*rotation_)
        scale, rotation, displacement = decompose_transformation_matrix(m)
        numpy.testing.assert_array_almost_equal(
            displacement, (0, 0, 0), err_msg="decomposed displacement is incorrect"
        )
        numpy.testing.assert_array_almost_equal(
            scale, (1, 1, 1), err_msg="decomposed scale is incorrect"
        )
        numpy.testing.assert_array_almost_equal(
            rotation, rotation_, err_msg="decomposed rotation is incorrect"
        )

        m = transform_matrix((1, 2, 3), rotation_, (1, 2, 3))
        scale, rotation, displacement = decompose_transformation_matrix(m)
        numpy.testing.assert_array_almost_equal(
            displacement, (1, 2, 3), err_msg="decomposed displacement is incorrect"
        )
        numpy.testing.assert_array_almost_equal(
            scale, (1, 2, 3), err_msg="decomposed scale is incorrect"
        )
        numpy.testing.assert_array_almost_equal(
            rotation, rotation_, err_msg="decomposed rotation is incorrect"
        )
Example #3
0
    def _rotate(self, angle: int):
        """Rotate the floating selection by the angle based on the camera rotation."""
        angle = math.radians(angle)
        ry, rx = self.canvas.camera.rotation
        if rx < -45:
            rotation_change = rotation_matrix_xyz(0, angle, 0)
        elif -45 <= rx < 45:
            if -135 <= ry < -45:
                # east
                rotation_change = rotation_matrix_xyz(angle, 0, 0)
            elif -45 <= ry < 45:
                # south
                rotation_change = rotation_matrix_xyz(0, 0, angle)
            elif 45 <= ry < 135:
                # west
                rotation_change = rotation_matrix_xyz(-angle, 0, 0)
            else:
                # north
                rotation_change = rotation_matrix_xyz(0, 0, -angle)
        else:
            rotation_change = rotation_matrix_xyz(0, -angle, 0)

        self._rotation.value = numpy.rad2deg(
            decompose_transformation_matrix(
                numpy.matmul(
                    rotation_change,
                    rotation_matrix_xyz(*self._rotation_radians())))[1])
        self._update_transform()
Example #4
0
 def test_chain_rotation_xy(self):
     numpy.testing.assert_array_equal(
         numpy.round(
             numpy.matmul(
                 numpy.matmul(
                     rotation_matrix_xyz(
                         *numpy.deg2rad([0, 90, 0])
                     ),  # y rotation applied second
                     rotation_matrix_xyz(
                         *numpy.deg2rad([90, 0, 0])
                     ),  # x rotation applied first
                 ),
                 (1, 1, 1, 1),
             )[:3],
             1,
         ),
         (1, -1, -1),
     )