示例#1
0
def orientation_matrix(euler1, euler2, euler3):
    """Input: Three Euler angles (Bunge convention), expressed in degrees
       Output: Cartesian coordinates of the orientation direction"""
    e1, e2, e3 = np.eye(3)  #standard basis (sample coord system)
    sample_basis = np.array([e1, e2, e3])

    deg2rad = np.pi / 180.0  #degree to radian conversion factor

    #rot1 = affine.rotation_matrix(euler1*deg2rad,axis=e3) @ sample_basis
    #rot2 = affine.rotation_matrix(euler2*deg2rad,axis=rot1.T[0]) @ rot1
    #rot3 = affine.rotation_matrix(euler3*deg2rad,axis=rot2.T[2]) @ rot2
    rot1 = affine.rotation_matrix(euler1 * deg2rad, axis=e3)
    rot2 = rot1 @ affine.rotation_matrix(euler2 * deg2rad, axis=e1)
    rot3 = rot2 @ affine.rotation_matrix(euler3 * deg2rad, axis=e3)
    return rot3
示例#2
0
    def test_random(self):
        """ Test that rotation_matrix() returns a valid rotation matrix
		for random axes and angles """
        axis = np.random.random((3,))
        angle = np.random.random()

        mat = tr.rotation_matrix(angle, axis)
        self.assertTrue(tr.is_rotation_matrix(mat))
示例#3
0
    def test_change_of_basis(self):
        """ Test that change_of_basis() returns a correct change-of-basis matrix"""

        b1 = np.array([[0, 0, 1], [1, 0, 0], [0, 1, 0]])

        # Generate a new basis as a rotation of pi/3 around z-axis
        b2 = np.dot(tr.rotation_matrix(np.pi / 3, axis=[0, 0, 1]), b1)

        cob = tr.change_of_basis(b1, b2)
        self.assertTrue(np.allclose(np.dot(cob, b1), b2))
示例#4
0
    def test_random(self):
        """ Test that translation_rotation_matrix() produces a matrix that correctly
		transforms a random point """
        pt = np.random.random((3,))

        axis = np.random.random((3,))
        angle = np.random.random()
        translation = np.random.random((3,))

        trmat = tr.translation_rotation_matrix(angle, axis, translation=translation)
        v1 = tr.transform(trmat, pt)  # translated rotated point

        # Transform the point once operator at a time
        v2 = tr.transform(tr.rotation_matrix(angle, axis), pt)
        v2 += translation

        self.assertTrue(np.allclose(v1, v2))
示例#5
0
    def test_from_rotation_matrix(self):
        """ test that the rotated identity operator is
		a rotation matrix"""
        self.assertTrue(
            tr.is_rotation_matrix(tr.rotation_matrix(np.pi / 3, axis=[0, 0, 1]))
        )