
    Ed*                     R    d dl mZ d dlmZmZmZ d dlmZ dgZ G d d          Z	dS )    )sympify)PointReferenceFrameDyadic)sympy_deprecation_warning	RigidBodyc                   f   e Zd ZdZd Zd Zd Zed             Zej	        d             Zed             Z
e
j	        d             Z
ed	             Zej	        d
             Zed             Zej	        d             Zed             Zd Zd Zd Zed             Zej	        d             Zd Zd ZdS )r   a  An idealized rigid body.

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

    This is essentially a container which holds the various components which
    describe a rigid body: a name, mass, center of mass, reference frame, and
    inertia.

    All of these need to be supplied on creation, but can be changed
    afterwards.

    Attributes
    ==========

    name : string
        The body's name.
    masscenter : Point
        The point which represents the center of mass of the rigid body.
    frame : ReferenceFrame
        The ReferenceFrame which the rigid body is fixed in.
    mass : Sympifyable
        The body's mass.
    inertia : (Dyadic, Point)
        The body's inertia about a point; stored in a tuple as shown above.

    Examples
    ========

    >>> from sympy import Symbol
    >>> from sympy.physics.mechanics import ReferenceFrame, Point, RigidBody
    >>> from sympy.physics.mechanics import outer
    >>> m = Symbol('m')
    >>> A = ReferenceFrame('A')
    >>> P = Point('P')
    >>> I = outer (A.x, A.x)
    >>> inertia_tuple = (I, P)
    >>> B = RigidBody('B', P, A, m, inertia_tuple)
    >>> # Or you could change them afterwards
    >>> m2 = Symbol('m2')
    >>> B.mass = m2

    c                     t          |t                    st          d          || _        || _        || _        || _        || _        d| _        d S )NzSupply a valid name.r   )	
isinstancestr	TypeError_name
masscentermassframeinertiapotential_energy)selfnamer   r   r   r   s         Alib/python3.11/site-packages/sympy/physics/mechanics/rigidbody.py__init__zRigidBody.__init__7   sT    $$$ 	42333
$	
 !    c                     | j         S N)r   r   s    r   __str__zRigidBody.__str__A   s
    zr   c                 *    |                                  S r   )r   r   s    r   __repr__zRigidBody.__repr__D   s    ||~~r   c                     | j         S r   )_framer   s    r   r   zRigidBody.frameG   s
    {r   c                 \    t          |t                    st          d          || _        d S )Nz/RigdBody frame must be a ReferenceFrame object.)r   r   r   r    )r   Fs     r   r   zRigidBody.frameK   s/    !^,, 	OMNNNr   c                     | j         S r   )_masscenterr   s    r   r   zRigidBody.masscenterQ   s    r   c                 \    t          |t                    st          d          || _        d S )Nz0RigidBody center of mass must be a Point object.)r   r   r   r$   )r   ps     r   r   zRigidBody.masscenterU   s2    !U## 	PNOOOr   c                     | j         S r   )_massr   s    r   r   zRigidBody.mass[   s
    zr   c                 .    t          |          | _        d S r   )r   r(   )r   ms     r   r   zRigidBody.mass_   s    QZZ


r   c                     | j         | j        fS r   )_inertia_inertia_pointr   s    r   r   zRigidBody.inertiac   s    t233r   c                 x   t          |d         t                    st          d          t          |d         t                    st          d          |d         | _        |d         | _        ddlm}  || j        | j	        
                    |d                   | j                  }|d         |z
  | _        d S )Nr   z*RigidBody inertia must be a Dyadic object.   z(RigidBody inertia must be about a Point.)inertia_of_point_mass)r   r   r   r   r,   r-   !sympy.physics.mechanics.functionsr0   r   r   pos_fromr   _central_inertia)r   Ir0   I_Ss_Os       r   r   zRigidBody.inertiag   s    !A$'' 	JHIII!A$&& 	HFGGG!d 	LKKKKK&&ty'+'?'?!'E'E'+z3 3 !"!vr   c                     | j         S )z"The body's central inertia dyadic.)r3   r   s    r   central_inertiazRigidBody.central_inertiax   s     $$r   c                 F    | j         | j                            |          z  S )a   Linear momentum of the rigid body.

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

        The linear momentum L, of a rigid body B, with respect to frame N is
        given by

        L = M * v*

        where M is the mass of the rigid body and v* is the velocity of
        the mass center of B in the frame, N.

        Parameters
        ==========

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

        Examples
        ========

        >>> from sympy.physics.mechanics import Point, ReferenceFrame, outer
        >>> from sympy.physics.mechanics import RigidBody, dynamicsymbols
        >>> from sympy.physics.vector import init_vprinting
        >>> init_vprinting(pretty_print=False)
        >>> M, v = dynamicsymbols('M v')
        >>> N = ReferenceFrame('N')
        >>> P = Point('P')
        >>> P.set_vel(N, v * N.x)
        >>> I = outer (N.x, N.x)
        >>> Inertia_tuple = (I, P)
        >>> B = RigidBody('B', P, N, M, Inertia_tuple)
        >>> B.linear_momentum(N)
        M*v*N.x

        )r   r   vel)r   r   s     r   linear_momentumzRigidBody.linear_momentum}   s"    N y4?..u5555r   c                    | j         }| j                            |          }| j        }| j                            |          }| j                            |          }|                    |          |                    ||z            z   S )a|  Returns the angular momentum of the rigid body about a point in the
        given frame.

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

        The angular momentum H of a rigid body B about some point O in a frame
        N is given by:

            H = I . w + r x Mv

        where I is the central inertia dyadic of B, w is the angular velocity
        of body B in the frame, N, r is the position vector from point O to the
        mass center of B, and v is the velocity of the mass center in the
        frame, N.

        Parameters
        ==========

        point : Point
            The point about which angular momentum is desired.
        frame : ReferenceFrame
            The frame in which angular momentum is desired.

        Examples
        ========

        >>> from sympy.physics.mechanics import Point, ReferenceFrame, outer
        >>> from sympy.physics.mechanics import RigidBody, dynamicsymbols
        >>> from sympy.physics.vector import init_vprinting
        >>> init_vprinting(pretty_print=False)
        >>> M, v, r, omega = dynamicsymbols('M v r omega')
        >>> N = ReferenceFrame('N')
        >>> b = ReferenceFrame('b')
        >>> b.set_ang_vel(N, omega * b.x)
        >>> P = Point('P')
        >>> P.set_vel(N, 1 * N.x)
        >>> I = outer(b.x, b.x)
        >>> B = RigidBody('B', P, b, M, (I, P))
        >>> B.angular_momentum(P, N)
        omega*b.x

        )	r7   r   
ang_vel_inr   r   r2   r9   dotcross)r   pointr   r4   wr*   rvs           r   angular_momentumzRigidBody.angular_momentum   sv    X  J!!%((IO$$U++O&&uuQxx!''!a%..((r   c                 @   | j                             |          | j        | j                             |          z  t          d          z  z  }| j        | j                            |          | j                            |          z  z  t          d          z  }||z   S )a>  Kinetic energy of the rigid body.

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

        The kinetic energy, T, of a rigid body, B, is given by

        'T = 1/2 (I omega^2 + m v^2)'

        where I and m are the central inertia dyadic and mass of rigid body B,
        respectively, omega is the body's angular velocity and v is the
        velocity of the body's mass center in the supplied ReferenceFrame.

        Parameters
        ==========

        frame : ReferenceFrame
            The RigidBody's angular velocity and the velocity of it's mass
            center are typically defined with respect to an inertial frame but
            any relevant frame in which the velocities are known can be supplied.

        Examples
        ========

        >>> from sympy.physics.mechanics import Point, ReferenceFrame, outer
        >>> from sympy.physics.mechanics import RigidBody
        >>> from sympy import symbols
        >>> M, v, r, omega = symbols('M v r omega')
        >>> N = ReferenceFrame('N')
        >>> b = ReferenceFrame('b')
        >>> b.set_ang_vel(N, omega * b.x)
        >>> P = Point('P')
        >>> P.set_vel(N, v * N.x)
        >>> I = outer (b.x, b.x)
        >>> inertia_tuple = (I, P)
        >>> B = RigidBody('B', P, b, M, inertia_tuple)
        >>> B.kinetic_energy(N)
        M*v**2/2 + omega**2/2

           )r   r<   r7   r   r   r   r9   )r   r   rotational_KEtranslational_KEs       r   kinetic_energyzRigidBody.kinetic_energy   s    T ..u559M
%%e,,:-07

9; ; !I)<)<U)C)CO&&*' (*1!**5 ///r   c                     | j         S )a  The potential energy of the RigidBody.

        Examples
        ========

        >>> from sympy.physics.mechanics import RigidBody, Point, outer, ReferenceFrame
        >>> from sympy import symbols
        >>> M, g, h = symbols('M g h')
        >>> b = ReferenceFrame('b')
        >>> P = Point('P')
        >>> I = outer (b.x, b.x)
        >>> Inertia_tuple = (I, P)
        >>> B = RigidBody('B', P, b, M, Inertia_tuple)
        >>> B.potential_energy = M * g * h
        >>> B.potential_energy
        M*g*h

        )_per   s    r   r   zRigidBody.potential_energy  s    * xr   c                 .    t          |          | _        dS )a  Used to set the potential energy of this RigidBody.

        Parameters
        ==========

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

        Examples
        ========

        >>> from sympy.physics.mechanics import Point, outer
        >>> from sympy.physics.mechanics import RigidBody, ReferenceFrame
        >>> from sympy import symbols
        >>> b = ReferenceFrame('b')
        >>> M, g, h = symbols('M g h')
        >>> P = Point('P')
        >>> I = outer (b.x, b.x)
        >>> Inertia_tuple = (I, P)
        >>> B = RigidBody('B', P, b, M, Inertia_tuple)
        >>> B.potential_energy = M * g * h

        N)r   rJ   r   scalars     r   r   zRigidBody.potential_energy#  s    4 6??r   c                 8    t          ddd           || _        d S )Nz
The sympy.physics.mechanics.RigidBody.set_potential_energy()
method is deprecated. Instead use

    B.potential_energy = scalar
            z1.5zdeprecated-set-potential-energy)deprecated_since_versionactive_deprecations_target)r   r   rL   s     r   set_potential_energyzRigidBody.set_potential_energy?  s6    ! "'#D		
 		
 		
 		
 !'r   c                    ddl m} | j                            |                              | j                  \  }}}| j         || j        |dz  |dz  z   |dz  |dz  z   |dz  |dz  z   | |z  | |z  | |z            z  }| j        |z   S )a  Returns the inertia dyadic of the body with respect to another
        point.

        Parameters
        ==========

        point : sympy.physics.vector.Point
            The point to express the inertia dyadic about.

        Returns
        =======

        inertia : sympy.physics.vector.Dyadic
            The inertia dyadic of the rigid body expressed about the provided
            point.

        r   )r   rE   )r1   r   r   r2   	to_matrixr   r   r7   )r   r?   r   abcr4   s          r   parallel_axiszRigidBody.parallel_axisN  s    & 	>=====/**511;;DJGG1aI
AqD1a4KA1ad !1G%'(b1fqb1fqb1f> > >#a''r   N)__name__
__module____qualname____doc__r   r   r   propertyr   setterr   r   r   r7   r:   rC   rH   r   rQ   rW    r   r   r   r   
   s       * *X" " "       X \  \
     X    
   X 
[    [  4 4 X4 ^. . ^.  % % X%'6 '6 '6R2) 2) 2)h00 00 00d   X, # # #6' ' '( ( ( ( (r   N)
sympy.core.backendr   sympy.physics.vectorr   r   r   sympy.utilities.exceptionsr   __all__r   r^   r   r   <module>rc      s    & & & & & & > > > > > > > > > > @ @ @ @ @ @-[( [( [( [( [( [( [( [( [( [(r   