Exemple #1
0
def test_from_euler_angles():
    ea1 = 1.4, 0.5, 2.3
    args = False, 'xyz'
    R1 = Rotation.from_euler_angles(ea1, *args)
    ea2 = R1.euler_angles(*args)
    assert allclose(ea1, ea2)

    alpha, beta, gamma = ea1
    xaxis, yaxis, zaxis = [1, 0, 0], [0, 1, 0], [0, 0, 1]
    Rx = Rotation.from_axis_and_angle(xaxis, alpha)
    Ry = Rotation.from_axis_and_angle(yaxis, beta)
    Rz = Rotation.from_axis_and_angle(zaxis, gamma)
    R2 = Rx * Ry * Rz
    assert np.allclose(R1, R2)
Exemple #2
0
def test_axis_and_angle():
    axis1 = normalize_vector([-0.043, -0.254, 0.617])
    angle1 = 0.1
    R = Rotation.from_axis_and_angle(axis1, angle1)
    axis2, angle2 = R.axis_and_angle
    assert allclose(axis1, axis2)
    assert allclose([angle1], [angle2])
Exemple #3
0
def test_basis_vectors():
    ea1 = 1.4, 0.5, 2.3
    args = False, 'xyz'
    R1 = Rotation.from_euler_angles(ea1, *args)
    R2 = [[-0.5847122176808724, -0.18803656702967916, 0.789147560317086],
          [-0.6544178905170501, -0.4655532858863264, -0.5958165511058404]]
    assert np.allclose(R1.basis_vectors, R2)
def concatenate():
    trans1 = [1, 2, 3]
    angle1 = [-2.142, 1.141, -0.142]
    T1 = Translation(trans1)
    R1 = Rotation.from_euler_angles(angle1)
    M1 = T1.concatenate(R1)
    assert np.allclose(M1, T1 * R1)
Exemple #5
0
def test_from_basis_vectors():
    xaxis = [0.68, 0.68, 0.27]
    yaxis = [-0.67, 0.73, -0.15]
    R = Rotation.from_basis_vectors(xaxis, yaxis)
    r = [[0.6807833515407016, -0.6687681611113407, -0.29880282253789103, 0.0],
         [0.6807833515407016, 0.7282315114847181, -0.07882160714891209, 0.0],
         [0.2703110366411609, -0.14975954908850603, 0.9510541192112079, 0.0],
         [0.0, 0.0, 0.0, 1.0]]
    assert np.allclose(R, r)
def test_rotation():
    angle1 = [-2.142, 1.141, -0.142]
    R = Rotation.from_euler_angles(angle1)
    r = [[0.41249169135312663, -0.8335562904208867, -0.3674704277413451, 0.0],
         [-0.05897071585157175, -0.4269749553355485, 0.9023385407861949, 0.0],
         [
             -0.9090506362335324, -0.35053715668381935, -0.22527903264048646,
             0.0
         ], [0.0, 0.0, 0.0, 1.0]]
    assert np.allclose(R, r)
def test_decomposed():
    trans1 = [1, 2, 3]
    angle1 = [-2.142, 1.141, -0.142]
    scale1 = [0.123, 2, 0.5]
    T1 = Translation(trans1)
    R1 = Rotation.from_euler_angles(angle1)
    S1 = Scale(scale1)
    M = (T1 * R1) * S1
    Sc, Sh, R, T, P = M.decomposed()
    assert S1 == Sc
    assert R1 == R
    assert T1 == T
def test_basis_vectors():
    trans1 = [1, 2, 3]
    angle1 = [-2.142, 1.141, -0.142]
    scale1 = [0.123, 2, 0.5]
    T1 = Translation(trans1)
    R1 = Rotation.from_euler_angles(angle1)
    S1 = Scale(scale1)
    M = (T1 * R1) * S1
    x, y = M.basis_vectors
    assert np.allclose(
        x,
        Vector(0.41249169135312663, -0.05897071585157175, -0.9090506362335324))
    assert np.allclose(
        y,
        Vector(-0.8335562904208867, -0.4269749553355485, -0.35053715668381935))
Exemple #9
0
    def decomposed(self):
        """Decompose the ``Transformation`` into its ``Scale``, ``Shear``,
        ``Rotation``, ``Translation`` and ``Perspective`` components.

        Returns
        -------
        5-tuple of Transformation
            The scale, shear, rotation, tranlation, and projection components
            of the current transformation.

        Examples
        --------
        >>> trans1 = [1, 2, 3]
        >>> angle1 = [-2.142, 1.141, -0.142]
        >>> scale1 = [0.123, 2, 0.5]
        >>> T1 = Translation(trans1)
        >>> R1 = Rotation.from_euler_angles(angle1)
        >>> S1 = Scale(scale1)
        >>> M = (T1 * R1) * S1
        >>> Sc, Sh, R, T, P = M.decomposed()
        >>> S1 == Sc
        True
        >>> R1 == R
        True
        >>> T1 == T
        True

        """
        from compas.geometry.transformations import Scale  # noqa: F811
        from compas.geometry.transformations import Shear
        from compas.geometry.transformations import Rotation  # noqa: F811
        from compas.geometry.transformations import Translation  # noqa: F811
        from compas.geometry.transformations import Projection

        sc, sh, a, t, p = decompose_matrix(self.matrix)
        Sc = Scale(sc)
        Sh = Shear.from_entries(sh)
        R = Rotation.from_euler_angles(a, static=True, axes='xyz')
        T = Translation(t)
        P = Projection.from_entries(p)
        return Sc, Sh, R, T, P
Exemple #10
0
def R():
    return Rotation.from_euler_angles([90, 0, 0])
Exemple #11
0
def test_euler_angles():
    ea1 = 1.4, 0.5, 2.3
    args = False, 'xyz'
    R1 = Rotation.from_euler_angles(ea1, *args)
    ea2 = R1.euler_angles(*args)
    assert allclose(ea1, ea2)
Exemple #12
0
def test_axis_angle_vector():
    aav1 = [-0.043, -0.254, 0.617]
    R = Rotation.from_axis_angle_vector(aav1)
    aav2 = R.axis_angle_vector
    assert allclose(aav1, aav2)
Exemple #13
0
def test_quaternion():
    q1 = [0.945, -0.021, -0.125, 0.303]
    R = Rotation.from_quaternion(q1)
    q2 = R.quaternion
    assert allclose(q1, q2, tol=1e-3)