ó
¡¼™\c           @   sn   d  d l  m Z d  d l m Z m Z m Z m Z d  d l m Z m	 Z	 d g Z
 d e e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   Symbol(   t	   RigidBodyt   Particlet   ReferenceFramet   inertia(   t   Pointt   Vectort   Bodyc           B   s8   e  Z d  Z d d d d d „ Z d d „ Z d „  Z RS(   s-  
    Body is a common representation of either a RigidBody or a Particle SymPy
    object depending on what is passed in during initialization. If a mass is
    passed in and central_inertia is left as None, the Particle object is
    created. Otherwise a RigidBody object will be created.

    The attributes that Body possesses will be the same as a Particle instance
    or a Rigid Body instance depending on which was created. Additional
    attributes are listed below.

    Attributes
    ==========

    name : string
        The body's name
    masscenter : Point
        The point which represents the center of mass of the rigid body
    frame : ReferenceFrame
        The reference frame which the body is fixed in
    mass : Sympifyable
        The body's mass
    inertia : (Dyadic, Point)
        The body's inertia around its center of mass. This attribute is specific
        to the rigid body form of Body and is left undefined for the Particle
        form
    loads : iterable
        This list contains information on the different loads acting on the
        Body. Forces are listed as a (point, vector) tuple and torques are
        listed as (reference frame, vector) tuples.

    Parameters
    ==========

    name : String
        Defines the name of the body. It is used as the base for defining
        body specific properties.
    masscenter : Point, optional
        A point that represents the center of mass of the body or particle.
        If no point is given, a point is generated.
    mass : Sympifyable, optional
        A Sympifyable object which represents the mass of the body. If no
        mass is passed, one is generated.
    frame : ReferenceFrame, optional
        The ReferenceFrame that represents the reference frame of the body.
        If no frame is given, a frame is generated.
    central_inertia : Dyadic, optional
        Central inertia dyadic of the body. If none is passed while creating
        RigidBody, a default inertia is generated.

    Examples
    ========

    Default behaviour. This results in the creation of a RigidBody object for
    which the mass, mass center, frame and inertia attributes are given default
    values. ::

        >>> from sympy.physics.mechanics import Body
        >>> body = Body('name_of_body')

    This next example demonstrates the code required to specify all of the
    values of the Body object. Note this will also create a RigidBody version of
    the Body object. ::

        >>> from sympy import Symbol
        >>> from sympy.physics.mechanics import ReferenceFrame, Point, inertia
        >>> from sympy.physics.mechanics import Body
        >>> mass = Symbol('mass')
        >>> masscenter = Point('masscenter')
        >>> frame = ReferenceFrame('frame')
        >>> ixx = Symbol('ixx')
        >>> body_inertia = inertia(frame, ixx, 0, 0)
        >>> body = Body('name_of_body', masscenter, mass, frame, body_inertia)

    The minimal code required to create a Particle version of the Body object
    involves simply passing in a name and a mass. ::

        >>> from sympy import Symbol
        >>> from sympy.physics.mechanics import Body
        >>> mass = Symbol('mass')
        >>> body = Body('name_of_body', mass=mass)

    The Particle version of the Body object can also receive a masscenter point
    and a reference frame, just not an inertia.
    c         C   s“  | |  _  g  |  _ | d  k r1 t | d ƒ } n  | d  k rP t | d ƒ } n  | d  k rï | d  k rï t | d ƒ } t | d ƒ } t | d ƒ } t | d ƒ }	 t | d ƒ }
 t | d ƒ } t | | | | |
 | |	 ƒ | f } n | | f } | d  k rt | d	 ƒ } n | } | j | d
 ƒ | d  k rs| d  k	 rs| |  _ | |  _	 t
 j |  | | | ƒ n t j |  | | | | | ƒ d  S(   Nt   _framet   _masscentert   _ixxt   _iyyt   _izzt   _izxt   _ixyt   _iyzt   _massi    (   t   namet   loadst   NoneR   R   R    R   t   set_velt   framet
   masscenterR   t   __init__R   (   t   selfR   R   t   massR   t   central_inertiat   ixxt   iyyt   izzt   izxt   ixyt   iyzt   _inertiaR   (    (    s;   lib/python2.7/site-packages/sympy/physics/mechanics/body.pyR   _   s2    				c         C   sn   t  | t ƒ s6 | d k r' |  j } q6 t d ƒ ‚ n  t  | t ƒ sT t d ƒ ‚ n  |  j j | | f ƒ d S(   sÃ  
        Adds a force to a point (center of mass by default) on the body.

        Parameters
        ==========

        vec: Vector
            Defines the force vector. Can be any vector w.r.t any frame or
            combinations of frames.
        point: Point, optional
            Defines the point on which the force is applied. Default is the
            Body's center of mass.

        Example
        =======

        The first example applies a gravitational force in the x direction of
        Body's frame to the body's center of mass. ::

            >>> from sympy import Symbol
            >>> from sympy.physics.mechanics import Body
            >>> body = Body('body')
            >>> g = Symbol('g')
            >>> body.apply_force(body.mass * g * body.frame.x)

        To apply force to any other point than center of mass, pass that point
        as well. This example applies a gravitational force to a point a
        distance l from the body's center of mass in the y direction. The
        force is again applied in the x direction. ::

            >>> from sympy import Symbol
            >>> from sympy.physics.mechanics import Body
            >>> body = Body('body')
            >>> g = Symbol('g')
            >>> l = Symbol('l')
            >>> point = body.masscenter.locatenew('force_point', l *
            ...                                   body.frame.y)
            >>> body.apply_force(body.mass * g * body.frame.x, point)

        s+   A Point must be supplied to apply force to.s)   A Vector must be supplied to apply force.N(   t
   isinstanceR   R   R   t	   TypeErrorR   R   t   append(   R   t   vect   point(    (    s;   lib/python2.7/site-packages/sympy/physics/mechanics/body.pyt   apply_force‡   s    *c         C   s;   t  | t ƒ s t d ƒ ‚ n  |  j j |  j | f ƒ d S(   s  
        Adds a torque to the body.

        Parameters
        ==========

        vec: Vector
            Defines the torque vector. Can be any vector w.r.t any frame or
            combinations of frame.

        Example
        =======

        This example adds a simple torque around the body's z axis. ::

            >>> from sympy import Symbol
            >>> from sympy.physics.mechanics import Body
            >>> body = Body('body')
            >>> T = Symbol('T')
            >>> body.apply_torque(T * body.frame.z)
        s(   A Vector must be supplied to add torque.N(   R"   R   R#   R   R$   R   (   R   R%   (    (    s;   lib/python2.7/site-packages/sympy/physics/mechanics/body.pyt   apply_torque»   s    N(   t   __name__t
   __module__t   __doc__R   R   R'   R(   (    (    (    s;   lib/python2.7/site-packages/sympy/physics/mechanics/body.pyR   	   s
   T	'4N(   t   sympy.core.backendR    t   sympy.physics.mechanicsR   R   R   R   t   sympy.physics.vectorR   R   t   __all__R   (    (    (    s;   lib/python2.7/site-packages/sympy/physics/mechanics/body.pyt   <module>   s   "	