예제 #1
0
def test_orienters():
    A = CoordSysCartesian('A')
    axis_orienter = AxisOrienter(a, A.k)
    B = body_orienter = BodyOrienter(a, b, c, '123')
    assert (B.angle1, B.angle2, B.angle3) == (a, b, c)
    assert B.rot_order == '123'
    B = BodyOrienter(a, b, c, Symbol('123'))
    assert B.rot_order == '123'
    space_orienter = SpaceOrienter(a, b, c, '123')
    Q = q_orienter = QuaternionOrienter(q1, q2, q3, q4)
    assert (Q.q0, Q.q1, Q.q2, Q.q3) == (q1, q2, q3, q4)
    assert axis_orienter.rotation_matrix(A) == Matrix([[cos(a),
                                                        sin(a), 0],
                                                       [-sin(a),
                                                        cos(a), 0], [0, 0, 1]])
    assert body_orienter.rotation_matrix() == Matrix(
        [[
            cos(b) * cos(c),
            sin(a) * sin(b) * cos(c) + sin(c) * cos(a),
            sin(a) * sin(c) - sin(b) * cos(a) * cos(c)
        ],
         [
             -sin(c) * cos(b), -sin(a) * sin(b) * sin(c) + cos(a) * cos(c),
             sin(a) * cos(c) + sin(b) * sin(c) * cos(a)
         ], [sin(b), -sin(a) * cos(b),
             cos(a) * cos(b)]])
    assert space_orienter.rotation_matrix() == Matrix(
        [[cos(b) * cos(c), sin(c) * cos(b), -sin(b)],
         [
             sin(a) * sin(b) * cos(c) - sin(c) * cos(a),
             sin(a) * sin(b) * sin(c) + cos(a) * cos(c),
             sin(a) * cos(b)
         ],
         [
             sin(a) * sin(c) + sin(b) * cos(a) * cos(c),
             -sin(a) * cos(c) + sin(b) * sin(c) * cos(a),
             cos(a) * cos(b)
         ]])
    assert q_orienter.rotation_matrix() == Matrix(
        [[
            q1**2 + q2**2 - q3**2 - q4**2, 2 * q1 * q4 + 2 * q2 * q3,
            -2 * q1 * q3 + 2 * q2 * q4
        ],
         [
             -2 * q1 * q4 + 2 * q2 * q3, q1**2 - q2**2 + q3**2 - q4**2,
             2 * q1 * q2 + 2 * q3 * q4
         ],
         [
             2 * q1 * q3 + 2 * q2 * q4, -2 * q1 * q2 + 2 * q3 * q4,
             q1**2 - q2**2 - q3**2 + q4**2
         ]])

    B = CoordSysCartesian('T')
    pytest.raises(ValueError, lambda: A.orient_new_axis('A', a, B.i))

    pytest.raises(TypeError, lambda: BodyOrienter(a, b, c, '12'))
    pytest.raises(TypeError, lambda: BodyOrienter(a, b, c, '111'))
예제 #2
0
def test_orienters():
    A = CoordSysCartesian('A')
    axis_orienter = AxisOrienter(a, A.k)
    body_orienter = BodyOrienter(a, b, c, '123')
    space_orienter = SpaceOrienter(a, b, c, '123')
    q_orienter = QuaternionOrienter(q1, q2, q3, q4)
    assert axis_orienter.rotation_matrix(A) == Matrix([[cos(a),
                                                        sin(a), 0],
                                                       [-sin(a),
                                                        cos(a), 0], [0, 0, 1]])
    assert body_orienter.rotation_matrix() == Matrix(
        [[
            cos(b) * cos(c),
            sin(a) * sin(b) * cos(c) + sin(c) * cos(a),
            sin(a) * sin(c) - sin(b) * cos(a) * cos(c)
        ],
         [
             -sin(c) * cos(b), -sin(a) * sin(b) * sin(c) + cos(a) * cos(c),
             sin(a) * cos(c) + sin(b) * sin(c) * cos(a)
         ], [sin(b), -sin(a) * cos(b),
             cos(a) * cos(b)]])
    assert space_orienter.rotation_matrix() == Matrix(
        [[cos(b) * cos(c), sin(c) * cos(b), -sin(b)],
         [
             sin(a) * sin(b) * cos(c) - sin(c) * cos(a),
             sin(a) * sin(b) * sin(c) + cos(a) * cos(c),
             sin(a) * cos(b)
         ],
         [
             sin(a) * sin(c) + sin(b) * cos(a) * cos(c),
             -sin(a) * cos(c) + sin(b) * sin(c) * cos(a),
             cos(a) * cos(b)
         ]])
    assert q_orienter.rotation_matrix() == Matrix(
        [[
            q1**2 + q2**2 - q3**2 - q4**2, 2 * q1 * q4 + 2 * q2 * q3,
            -2 * q1 * q3 + 2 * q2 * q4
        ],
         [
             -2 * q1 * q4 + 2 * q2 * q3, q1**2 - q2**2 + q3**2 - q4**2,
             2 * q1 * q2 + 2 * q3 * q4
         ],
         [
             2 * q1 * q3 + 2 * q2 * q4, -2 * q1 * q2 + 2 * q3 * q4,
             q1**2 - q2**2 - q3**2 + q4**2
         ]])
예제 #3
0
def test_orient_new_methods():
    N = CoordSysCartesian('N')
    orienter1 = AxisOrienter(q4, N.j)
    orienter2 = SpaceOrienter(q1, q2, q3, '123')
    orienter3 = QuaternionOrienter(q1, q2, q3, q4)
    orienter4 = BodyOrienter(q1, q2, q3, '123')
    D = N.orient_new('D', (orienter1, ))
    E = N.orient_new('E', (orienter2, ))
    F = N.orient_new('F', (orienter3, ))
    G = N.orient_new('G', (orienter4, ))
    assert D == N.orient_new_axis('D', q4, N.j)
    assert E == N.orient_new_space('E', q1, q2, q3, '123')
    assert F == N.orient_new_quaternion('F', q1, q2, q3, q4)
    assert G == N.orient_new_body('G', q1, q2, q3, '123')
예제 #4
0
    def orient_new_space(self,
                         name,
                         angle1,
                         angle2,
                         angle3,
                         rotation_order,
                         location=None,
                         vector_names=None,
                         variable_names=None):
        """
        Space rotation is similar to Body rotation, but the rotations
        are applied in the opposite order.

        Parameters
        ==========

        name : string
            The name of the new coordinate system

        angle1, angle2, angle3 : Expr
            Three successive angles to rotate the coordinate system by

        rotation_order : string
            String defining the order of axes for rotation

        location : Vector(optional)
            The location of the new coordinate system's origin wrt this
            system's origin. If not specified, the origins are taken to
            be coincident.

        vector_names, variable_names : iterable(optional)
            Iterables of 3 strings each, with custom names for base
            vectors and base scalars of the new system respectively.
            Used for simple str printing.

        See Also
        ========

        diofant.vector.coordsysrect.CoordSysCartesian.orient_new_body :
            method to orient via Euler angles

        Examples
        ========

        >>> from diofant.vector import CoordSysCartesian
        >>> from diofant import symbols
        >>> q1, q2, q3 = symbols('q1 q2 q3')
        >>> N = CoordSysCartesian('N')

        To orient a coordinate system D with respect to N, each
        sequential rotation is always about N's orthogonal unit vectors.
        For example, a '123' rotation will specify rotations about
        N.i, then N.j, then N.k.
        Therefore,

        >>> D = N.orient_new_space('D', q1, q2, q3, '312')

        is same as

        >>> B = N.orient_new_axis('B', q1, N.i)
        >>> C = B.orient_new_axis('C', q2, N.j)
        >>> D = C.orient_new_axis('D', q3, N.k)

        """

        orienter = SpaceOrienter(angle1, angle2, angle3, rotation_order)
        return self.orient_new(name,
                               orienter,
                               location=location,
                               vector_names=vector_names,
                               variable_names=variable_names)