B
    ˜‘[$  ã               @   sB   d dl mZmZ d dlmZ d dlmZ dgZG dd„ deƒZ	dS )é    )Úprint_functionÚdivision)Úsympify)ÚPointÚParticlec               @   sŠ   e Zd ZdZdd„ Zdd„ ZeZedd„ ƒZej	dd„ ƒZed	d
„ ƒZ
e
j	dd
„ ƒZ
dd„ Zdd„ Zdd„ Zedd„ ƒZej	dd„ ƒZdS )r   aû  A particle.

    Particles have a non-zero mass and lack spatial extension; they take up no
    space.

    Values need to be supplied on initialization, but can be changed later.

    Parameters
    ==========
    name : str
        Name of particle
    point : Point
        A physics/mechanics Point which represents the position, velocity, and
        acceleration of this Particle
    mass : sympifyable
        A SymPy expression representing the Particle's mass

    Examples
    ========

    >>> from sympy.physics.mechanics import Particle, Point
    >>> from sympy import Symbol
    >>> po = Point('po')
    >>> m = Symbol('m')
    >>> pa = Particle('pa', po, m)
    >>> # Or you could change these later
    >>> pa.mass = m
    >>> pa.point = po

    c             C   s.   t |tƒstdƒ‚|| _|| _|| _d| _d S )NzSupply a valid name.r   )Ú
isinstanceÚstrÚ	TypeErrorÚ_nameÚmassÚpointÚpotential_energy)ÚselfÚnamer   r   © r   ú?lib/python3.7/site-packages/sympy/physics/mechanics/particle.pyÚ__init__)   s    
zParticle.__init__c             C   s   | j S )N)r
   )r   r   r   r   Ú__str__1   s    zParticle.__str__c             C   s   | j S )zMass of the particle.)Ú_mass)r   r   r   r   r   6   s    zParticle.massc             C   s   t |ƒ| _d S )N)r   r   )r   Úvaluer   r   r   r   ;   s    c             C   s   | j S )zPoint of the particle.)Ú_point)r   r   r   r   r   ?   s    zParticle.pointc             C   s   t |tƒstdƒ‚|| _d S )Nz0Particle point attribute must be a Point object.)r   r   r	   r   )r   Úpr   r   r   r   D   s    
c             C   s   | j | j |¡ S )a  Linear momentum of the particle.

        The linear momentum L, of a particle P, with respect to frame N is
        given by

        L = m * v

        where m is the mass of the particle, and v is the velocity of the
        particle in the frame N.

        Parameters
        ==========

        frame : ReferenceFrame
            The frame in which linear momentum is desired.

        Examples
        ========

        >>> from sympy.physics.mechanics import Particle, Point, ReferenceFrame
        >>> from sympy.physics.mechanics import dynamicsymbols
        >>> m, v = dynamicsymbols('m v')
        >>> N = ReferenceFrame('N')
        >>> P = Point('P')
        >>> A = Particle('A', P, m)
        >>> P.set_vel(N, v * N.x)
        >>> A.linear_momentum(N)
        m*v*N.x

        )r   r   Úvel)r   Úframer   r   r   Úlinear_momentumJ   s     zParticle.linear_momentumc             C   s   | j  |¡| j| j  |¡ A S )a  Angular momentum of the particle about the point.

        The angular momentum H, about some point O of a particle, P, is given
        by:

        H = r x m * v

        where r is the position vector from point O to the particle P, m is
        the mass of the particle, and v is the velocity of the particle in
        the inertial frame, N.

        Parameters
        ==========

        point : Point
            The point about which angular momentum of the particle is desired.

        frame : ReferenceFrame
            The frame in which angular momentum is desired.

        Examples
        ========

        >>> from sympy.physics.mechanics import Particle, Point, ReferenceFrame
        >>> from sympy.physics.mechanics import dynamicsymbols
        >>> m, v, r = dynamicsymbols('m v r')
        >>> N = ReferenceFrame('N')
        >>> O = Point('O')
        >>> A = O.locatenew('A', r * N.x)
        >>> P = Particle('P', A, m)
        >>> P.point.set_vel(N, v * N.y)
        >>> P.angular_momentum(O, N)
        m*r*v*N.z

        )r   Zpos_fromr   r   )r   r   r   r   r   r   Úangular_momentuml   s    %zParticle.angular_momentumc             C   s&   | j tdƒ | j |¡ | j |¡@ S )aw  Kinetic energy of the particle

        The kinetic energy, T, of a particle, P, is given by

        'T = 1/2 m v^2'

        where m is the mass of particle P, and v is the velocity of the
        particle in the supplied ReferenceFrame.

        Parameters
        ==========

        frame : ReferenceFrame
            The Particle's velocity is typically defined with respect to
            an inertial frame but any relevant frame in which the velocity is
            known can be supplied.

        Examples
        ========

        >>> from sympy.physics.mechanics import Particle, Point, ReferenceFrame
        >>> from sympy import symbols
        >>> m, v, r = symbols('m v r')
        >>> N = ReferenceFrame('N')
        >>> O = Point('O')
        >>> P = Particle('P', O, m)
        >>> P.point.set_vel(N, v * N.y)
        >>> P.kinetic_energy(N)
        m*v**2/2

        é   )r   r   r   r   )r   r   r   r   r   Úkinetic_energy“   s    !zParticle.kinetic_energyc             C   s   | j S )aw  The potential energy of the Particle.

        Examples
        ========

        >>> from sympy.physics.mechanics import Particle, Point
        >>> from sympy import symbols
        >>> m, g, h = symbols('m g h')
        >>> O = Point('O')
        >>> P = Particle('P', O, m)
        >>> P.potential_energy = m * g * h
        >>> P.potential_energy
        g*h*m

        )Ú_pe)r   r   r   r   r   ·   s    zParticle.potential_energyc             C   s   t |ƒ| _dS )aØ  Used to set the potential energy of the Particle.

        Parameters
        ==========

        scalar : Sympifyable
            The potential energy (a scalar) of the Particle.

        Examples
        ========

        >>> from sympy.physics.mechanics import Particle, Point
        >>> from sympy import symbols
        >>> m, g, h = symbols('m g h')
        >>> O = Point('O')
        >>> P = Particle('P', O, m)
        >>> P.potential_energy = m * g * h

        N)r   r   )r   Zscalarr   r   r   r   Ë   s    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__repr__Úpropertyr   Úsetterr   r   r   r   r   r   r   r   r   r   	   s   "'$N)
Z
__future__r   r   Zsympy.core.backendr   Zsympy.physics.vectorr   Ú__all__Úobjectr   r   r   r   r   Ú<module>   s   