o
    oh/(                     @   sj   d dl mZmZ d dlmZmZmZmZ d dlm	Z	 d dl
mZmZ d dlmZ dgZG dd de	ZdS )	    )SymbolS)ReferenceFrameDyadicPointdot)BodyBase)inertia_of_point_massInertia)sympy_deprecation_warning	RigidBodyc                       s   e Zd ZdZ		d  fdd	Zdd Zedd Zejd	d Zed
d Z	edd Z
edd 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dd Zd!ddZ  Z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.
    potential_energy : Sympifyable
        The potential energy of the RigidBody.

    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

    Nc              
      s   t  ||| |d u rt| d}|| _|d u rRt| d}t| d}t| d}t| d}	t| d}
t| d}t| j| j||||
||	}|| _d S )N_frame_ixx_iyy_izz_izx_ixy_iyz)	super__init__r   framer   r
   from_inertia_scalars
masscenterinertia)selfnamer   r   massr   ixxiyyizzizxixyiyz	__class__ u/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/physics/mechanics/rigidbody.pyr   9   s   
zRigidBody.__init__c                 C   sJ   | j j dt| j dt| j dt| j dt| j dt| j dS )N(z, masscenter=z, frame=z, mass=z
, inertia=))r$   __name__reprr   r   r   r   r   r   r%   r%   r&   __repr__J   s   zRigidBody.__repr__c                 C      | j S )z%The ReferenceFrame fixed to the body.)r   r+   r%   r%   r&   r   O      zRigidBody.framec                 C   s   t |ts	td|| _d S )Nz0RigidBody frame must be a ReferenceFrame object.)
isinstancer   	TypeErrorr   )r   Fr%   r%   r&   r   T   s   

c                 C      | j jS )z3The basis Vector for the body, in the x direction. )r   xr+   r%   r%   r&   r3   Z      zRigidBody.xc                 C   r2   )z3The basis Vector for the body, in the y direction. )r   yr+   r%   r%   r&   r5   _   r4   zRigidBody.yc                 C   r2   )z3The basis Vector for the body, in the z direction. )r   zr+   r%   r%   r&   r6   d   r4   zRigidBody.zc                 C   r-   )z<The body's inertia about a point; stored as (Dyadic, Point).)_inertiar+   r%   r%   r&   r   i   r.   zRigidBody.inertiac                 C   sr   t |dkst|d trt|d tstdt|d |d | _t| j| j	
|d | j}|d | | _d S )N   r      z>RigidBody inertia must be a tuple of the form (Dyadic, Point).)lenr/   r   r   r0   r
   r7   r	   r   r   pos_fromr   _central_inertia)r   II_Ss_Or%   r%   r&   r   n   s   (c                 C   r-   )z"The body's central inertia dyadic.)r<   r+   r%   r%   r&   central_inertia}   r.   zRigidBody.central_inertiac                 C   s$   t |ts	tdt|| j| _d S )Nz*RigidBody inertia must be a Dyadic object.)r/   r   r0   r
   r   r   )r   r=   r%   r%   r&   r?      s   
c                 C   s   | j | j| 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   r%   r%   r&   linear_momentum   s   'zRigidBody.linear_momentumc                 C   sH   | j }| j|}| j}| j|}| j|}|||||  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 = dot(I, w) + cross(r, m * v)``

        where I and m are the central inertia dyadic and mass of rigid body 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

        )	r?   r   
ang_vel_inr   r   r;   r@   r   cross)r   pointr   r=   wmrvr%   r%   r&   angular_momentum   s   ,zRigidBody.angular_momentumc                 C   sV   t jt| j|t| j| j| }t j| j t| j|| j| }|| S )a[  Kinetic energy of the rigid body.

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

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

        ``T = 1/2 * (dot(dot(I, w), w) + dot(m * v, v))``

        where I and m are the central inertia dyadic and mass of rigid body B
        respectively, w 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   Halfr   r   rB   r?   r   r   r@   )r   r   rotational_KEtranslational_KEr%   r%   r&   kinetic_energy   s   +

zRigidBody.kinetic_energyc                 C   s   t d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   potential_energy)r   scalarr%   r%   r&   set_potential_energy  s   

zRigidBody.set_potential_energyc                 C   s*   |du r| j }| jt| j| j|| 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.
        frame : sympy.physics.vector.ReferenceFrame
            The reference frame used to construct the dyadic.

        Returns
        =======

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

        N)r   r?   r	   r   r   r;   )r   rD   r   r%   r%   r&   parallel_axis$  s
   zRigidBody.parallel_axis)NNNN)N)r)   
__module____qualname____doc__r   r,   propertyr   setterr3   r5   r6   r   r?   rA   rI   rM   rR   rS   __classcell__r%   r%   r#   r&   r   
   s:    .








)42N)sympyr   r   sympy.physics.vectorr   r   r   r   !sympy.physics.mechanics.body_baser   sympy.physics.mechanics.inertiar	   r
   sympy.utilities.exceptionsr   __all__r   r%   r%   r%   r&   <module>   s    