U
    ZÊ¹j  ã                   @   sj   d dl mZ d dlmZmZmZmZ d dlmZ dddgZ	ddd„Z
dd„ ZG d	d„ dedd
dgƒƒZdS )é    )Úsympify)ÚPointÚDyadicÚReferenceFrameÚouter)Ú
namedtupleÚinertiaÚinertia_of_point_massÚInertiac                 C   sì   t | tƒstdƒ‚t|ƒt|ƒt|ƒ  }}}t|ƒt|ƒt|ƒ  }}}|t| j| jƒ |t| j| jƒ  |t| j| jƒ  |t| j| jƒ  |t| j| jƒ  |t| j| jƒ  |t| j| jƒ  |t| j| jƒ  |t| j| jƒ  S )a~  Simple way to create inertia Dyadic object.

    Explanation
    ===========

    Creates an inertia Dyadic based on the given tensor values and a body-fixed
    reference frame.

    Parameters
    ==========

    frame : ReferenceFrame
        The frame the inertia is defined in.
    ixx : Sympifyable
        The xx element in the inertia dyadic.
    iyy : Sympifyable
        The yy element in the inertia dyadic.
    izz : Sympifyable
        The zz element in the inertia dyadic.
    ixy : Sympifyable
        The xy element in the inertia dyadic.
    iyz : Sympifyable
        The yz element in the inertia dyadic.
    izx : Sympifyable
        The zx element in the inertia dyadic.

    Examples
    ========

    >>> from sympy.physics.mechanics import ReferenceFrame, inertia
    >>> N = ReferenceFrame('N')
    >>> inertia(N, 1, 2, 3)
    (N.x|N.x) + 2*(N.y|N.y) + 3*(N.z|N.z)

    z%Need to define the inertia in a frame)Ú
isinstancer   Ú	TypeErrorr   r   ÚxÚyÚz)ÚframeÚixxÚiyyÚizzÚixyÚiyzÚizx© r   ú^/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/physics/mechanics/inertia.pyr      s&    %
"ÿÿþþýýüc                 C   sB   | t |j|jƒt |j|jƒ t |j|jƒ | |¡ t ||ƒ  S )aO  Inertia dyadic of a point mass relative to point O.

    Parameters
    ==========

    mass : Sympifyable
        Mass of the point mass
    pos_vec : Vector
        Position from point O to point mass
    frame : ReferenceFrame
        Reference frame to express the dyadic in

    Examples
    ========

    >>> from sympy import symbols
    >>> from sympy.physics.mechanics import ReferenceFrame, inertia_of_point_mass
    >>> N = ReferenceFrame('N')
    >>> r, m = symbols('r m')
    >>> px = r * N.x
    >>> inertia_of_point_mass(m, px, N)
    m*r**2*(N.y|N.y) + m*r**2*(N.z|N.z)

    )r   r   r   r   Údot)ZmassZpos_vecr   r   r   r   r	   8   s    ÿþýýÿc                       sF   e Zd ZdZ‡ fdd„Zeddd„ƒZdd„ Zd	d
„ ZeZ	eZ
‡  ZS )r
   ay  Inertia object consisting of a Dyadic and a Point of reference.

    Explanation
    ===========

    This is a simple class to store the Point and Dyadic, belonging to an
    inertia.

    Attributes
    ==========

    dyadic : Dyadic
        The dyadic of the inertia.
    point : Point
        The reference point of the inertia.

    Examples
    ========

    >>> from sympy.physics.mechanics import ReferenceFrame, Point, Inertia
    >>> N = ReferenceFrame('N')
    >>> Po = Point('Po')
    >>> Inertia(N.x.outer(N.x) + N.y.outer(N.y) + N.z.outer(N.z), Po)
    ((N.x|N.x) + (N.y|N.y) + (N.z|N.z), Po)

    In the example above the Dyadic was created manually, one can however also
    use the ``inertia`` function for this or the class method ``from_tensor`` as
    shown below.

    >>> Inertia.from_inertia_scalars(Po, N, 1, 1, 1)
    ((N.x|N.x) + (N.y|N.y) + (N.z|N.z), Po)

    c                    sR   t |tƒrt |tƒr|| }}t |tƒs0tdƒ‚t |tƒsBtdƒ‚tƒ  | ||¡S )Nz'Reference point should be of type Pointz-Inertia value should be expressed as a Dyadic)r   r   r   r   ÚsuperÚ__new__)ÚclsÚdyadicÚpoint©Ú	__class__r   r   r   {   s    


zInertia.__new__r   c	           	   	   C   s   | t |||||||ƒ|ƒS )a¾  Simple way to create an Inertia object based on the tensor values.

        Explanation
        ===========

        This class method uses the :func`~.inertia` to create the Dyadic based
        on the tensor values.

        Parameters
        ==========

        point : Point
            The reference point of the inertia.
        frame : ReferenceFrame
            The frame the inertia is defined in.
        ixx : Sympifyable
            The xx element in the inertia dyadic.
        iyy : Sympifyable
            The yy element in the inertia dyadic.
        izz : Sympifyable
            The zz element in the inertia dyadic.
        ixy : Sympifyable
            The xy element in the inertia dyadic.
        iyz : Sympifyable
            The yz element in the inertia dyadic.
        izx : Sympifyable
            The zx element in the inertia dyadic.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.mechanics import ReferenceFrame, Point, Inertia
        >>> ixx, iyy, izz, ixy, iyz, izx = symbols('ixx iyy izz ixy iyz izx')
        >>> N = ReferenceFrame('N')
        >>> P = Point('P')
        >>> I = Inertia.from_inertia_scalars(P, N, ixx, iyy, izz, ixy, iyz, izx)

        The tensor values can easily be seen when converting the dyadic to a
        matrix.

        >>> I.dyadic.to_matrix(N)
        Matrix([
        [ixx, ixy, izx],
        [ixy, iyy, iyz],
        [izx, iyz, izz]])

        )r   )	r   r   r   r   r   r   r   r   r   r   r   r   Úfrom_inertia_scalars…   s    3zInertia.from_inertia_scalarsc                 C   s"   t d| jj› d|jj› d�ƒ‚d S )Nz$unsupported operand type(s) for +: 'ú' and 'ú'©r   r    Ú__name__©ÚselfÚotherr   r   r   Ú__add__º   s    zInertia.__add__c                 C   s"   t d| jj› d|jj› d�ƒ‚d S )Nz$unsupported operand type(s) for *: 'r"   r#   r$   r&   r   r   r   Ú__mul__¿   s    zInertia.__mul__)r   r   r   )r%   Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr!   r)   r*   Ú__radd__Ú__rmul__Ú__classcell__r   r   r   r   r
   Y   s   !
  ÿ4r   r   N)r   r   r   )Zsympyr   Zsympy.physics.vectorr   r   r   r   Úcollectionsr   Ú__all__r   r	   r
   r   r   r   r   Ú<module>   s   

0!