o
    oh`                     @   sV  d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
mZmZ d dlmZ d dlmZ ddlmZmZ ddlmZmZ ddlmZ dd	lmZmZmZmZmZ d d
lm Z  d dl!m"Z" g dZ#dd Z$e$ j%ej$j%7  _%dd Z&e& j%ej&j%7  _%d$ddZ'd%ddZ(dd Z)e) j%ej)j%7  _%d&ddZ*dd Z+dd Z,d'd d!Z-ed"e-_.d#e-_/dS )(    )reduce)
sympifydiffsincosMatrixsymbolsFunctionSSymbollinear_eq_to_matrix)	integratetrigsimp   )Vector_check_vector)CoordinateSym_check_frame)Dyadic)vprintvsprintvpprintvlatexinit_vprinting)iterable)	translate)crossdotexpresstime_derivativeouterkinematic_equationsget_motion_paramspartial_velocitydynamicsymbolsr   r   r   r   r   c                 C   s   t | ttfstd| |A S )z7Cross product convenience wrapper for Vector.cross(): 
z$Cross product is between two vectors
isinstancer   r   	TypeErrorvec1vec2 r,   r/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/physics/vector/functions.pyr         r   c                 C   s   t | ttfstd| |@ S )z3Dot product convenience wrapper for Vector.dot(): 
z"Dot product is between two vectorsr&   r)   r,   r,   r-   r      r.   r   NFc              	   C   s  t | | dkr
| S t| tre|r-dd | jD }i }|D ]
}||| q| |} tg }| jD ].}|d |kr[||d |d  }	tjrQ|		dd }	|t|	|fg7 }q4|t|g7 }q4|S t| t
r|du rp|}t | t
d}
| jD ]}|
t|d ||dt|d ||dt|d	 ||dB  7 }
q{|
S |rt }t| } | jD ]}t|tr|j|kr||j qi }|D ]
}||| q| |S | S )
a  
    Global function for 'express' functionality.

    Re-expresses a Vector, scalar(sympyfiable) or Dyadic in given frame.

    Refer to the local methods of Vector and Dyadic for details.
    If 'variables' is True, then the coordinate variables (CoordinateSym
    instances) of other frames present in the vector/scalar field or
    dyadic expression are also substituted in terms of the base scalars of
    this frame.

    Parameters
    ==========

    expr : Vector/Dyadic/scalar(sympyfiable)
        The expression to re-express in ReferenceFrame 'frame'

    frame: ReferenceFrame
        The reference frame to express expr in

    frame2 : ReferenceFrame
        The other frame required for re-expression(only for Dyadic expr)

    variables : boolean
        Specifies whether to substitute the coordinate variables present
        in expr, in terms of those of frame

    Examples
    ========

    >>> from sympy.physics.vector import ReferenceFrame, outer, dynamicsymbols
    >>> from sympy.physics.vector import init_vprinting
    >>> init_vprinting(pretty_print=False)
    >>> N = ReferenceFrame('N')
    >>> q = dynamicsymbols('q')
    >>> B = N.orientnew('B', 'Axis', [q, N.z])
    >>> d = outer(N.x, N.x)
    >>> from sympy.physics.vector import express
    >>> express(d, B, N)
    cos(q)*(B.x|N.x) - sin(q)*(B.y|N.x)
    >>> express(B.x, N)
    cos(q)*N.x + sin(q)*N.y
    >>> express(N[0], B, variables=True)
    B_x*cos(q) - B_y*sin(q)

    r   c                 S   s   g | ]}|d  qS )r,   ).0xr,   r,   r-   
<listcomp>b       zexpress.<locals>.<listcomp>r   c                 S   s   t | ddS )Nfu)methodr   )r1   r,   r,   r-   <lambda>m   s   zexpress.<locals>.<lambda>N	variables   )r   r'   r   argsupdatevariable_mapsubsdcmsimp	applyfuncr   r   setr   free_symbolsr   frameadd)exprrC   frame2r8   
frame_list	subs_dictfoutvecvtempol	frame_setr1   r,   r,   r-   r   (   sV   0






r   c                 C   st  t j}t| |dkr| S |d dks|dk rtdt| treg }| jD ]3}|d |kr?|t|d |dd||fg7 }q%|t	t|g|d |d 
|t|gA  j7 }q%t|}t	|||d S t| trtd}| jD ]5}||d ||d |d B  7 }||d t	|d ||d B  7 }||d |d t	|d |B  7 }qqt	|||d S tt| |dd||S )a  
    Calculate the time derivative of a vector/scalar field function
    or dyadic expression in given frame.

    References
    ==========

    https://en.wikipedia.org/wiki/Rotating_reference_frame#Time_derivatives_in_the_two_frames

    Parameters
    ==========

    expr : Vector/Dyadic/sympifyable
        The expression whose time derivative is to be calculated

    frame : ReferenceFrame
        The reference frame to calculate the time derivative in

    order : integer
        The order of the derivative to be calculated

    Examples
    ========

    >>> from sympy.physics.vector import ReferenceFrame, dynamicsymbols
    >>> from sympy.physics.vector import init_vprinting
    >>> init_vprinting(pretty_print=False)
    >>> from sympy import Symbol
    >>> q1 = Symbol('q1')
    >>> u1 = dynamicsymbols('u1')
    >>> N = ReferenceFrame('N')
    >>> A = N.orientnew('A', 'Axis', [q1, N.x])
    >>> v = u1 * N.x
    >>> A.set_ang_vel(N, 10*A.x)
    >>> from sympy.physics.vector import time_derivative
    >>> time_derivative(v, N)
    u1'*N.x
    >>> time_derivative(u1*A[0], N)
    N_x*u1'
    >>> B = N.orientnew('B', 'Axis', [u1, N.z])
    >>> from sympy.physics.vector import outer
    >>> d = outer(N.x, N.x)
    >>> time_derivative(d, B)
    - u1'*(N.y|N.x) - u1'*(N.x|N.y)

    r   r   z"Unsupported value of order enteredTr7   r9   )r%   _tr   
ValueErrorr'   r   r:   r   r   r    
ang_vel_inr   )rE   rC   ordertoutlistrK   rJ   rM   r,   r,   r-   r       s8   0




""$r    c                 C   s   t | ts	td| |S )z6Outer product convenience wrapper for Vector.outer():
z$Outer product is between two Vectors)r'   r   r(   r!   r)   r,   r,   r-   r!      s   

r!    c                 C   s	  d}t t|dd}| }t| ttfstdt| dkr#tdt|ttfs.td|dv r||vr;td	t|dkrEtd
| \}}}||  krY|  krYdkran nt	j
gd S |\}}	}
dd |D \}}}t|t|	t|
g\}}}t|t|	t|
g\}}}|dkr|dkr||| ||  |  |||  ||  || | ||  | |  | gS |dkr||| ||  |  |||  ||  || | | ||  | |  gS |dkr|| | ||  |  |||  ||  ||| ||  | |  | gS |dkr:||| ||  |  |||  ||  ||| ||  | |  | gS |dkrd||| ||  |  |||  ||  ||| ||  | |  | gS |dkr||| ||  |  |||  ||  || || ||  | |  gS |dkr||| ||  |  |||  ||  || || ||  | |  gS |dkr|| | ||  |  |||  ||  || || ||  | |  gS |dkr||| ||  |  |||  ||  || | ||  | |  | gS |dkr8||| ||  |  |||  ||  ||| ||  | |  | gS |dkrb||| ||  |  |||  ||  ||| ||  | |  | gS |dkr|| | ||  |  |||  ||  ||| ||  | |  | gS |dkr|dkr|| || ||  | |  |||  ||  ||| ||  |  gS |dkr||| ||  | |  | |||  ||  ||| ||  |  gS |dkr||| ||  | |  | |||  ||  ||| ||  |  gS |dkr;|| | | ||  | |  |||  ||  ||| ||  |  gS |dkrf||| ||  | |  | |||  ||  || | ||  |  gS |dkr|| | ||  | |  | |||  ||  ||| ||  |  gS |dkr|| || ||  | |  |||  ||  ||| ||  |  gS |dkr|| || ||  | |  |||  ||  || | ||  |  gS |dkr|| | ||  | |  | |||  ||  ||| ||  |  gS |dkr;||| ||  | |  | |||  ||  ||| ||  |  gS |dkre||| ||  | |  | |||  ||  ||| ||  |  gS |dkr||| ||  | |  | |||  ||  || | ||  |  gS d$S d$S |dkr|dkrtdt|dkrtd |\}}}}t| dg }t|| ||g||| |g| |||g| | | |gg}td!d ||||fD }t|jd"|j |j  S td#)%a  Gives equations relating the qdot's to u's for a rotation type.

    Supply rotation type and order as in orient. Speeds are assumed to be
    body-fixed; if we are defining the orientation of B in A using by rot_type,
    the angular velocity of B in A is assumed to be in the form: speed[0]*B.x +
    speed[1]*B.y + speed[2]*B.z

    Parameters
    ==========

    speeds : list of length 3
        The body fixed angular velocity measure numbers.
    coords : list of length 3 or 4
        The coordinates used to define the orientation of the two frames.
    rot_type : str
        The type of rotation used to create the equations. Body, Space, or
        Quaternion only
    rot_order : str or int
        If applicable, the order of a series of rotations.

    Examples
    ========

    >>> from sympy.physics.vector import dynamicsymbols
    >>> from sympy.physics.vector import kinematic_equations, vprint
    >>> u1, u2, u3 = dynamicsymbols('u1 u2 u3')
    >>> q1, q2, q3 = dynamicsymbols('q1 q2 q3')
    >>> vprint(kinematic_equations([u1,u2,u3], [q1,q2,q3], 'body', '313'),
    ...     order=None)
    [-(u1*sin(q3) + u2*cos(q3))/sin(q2) + q1', -u1*cos(q3) + u2*sin(q3) + q2', (u1*sin(q3) + u2*cos(q3))*cos(q2)/sin(q2) - u3 + q3']

    )123231312132213321121131212232313323123rU   XYZxyz123123zNeed to supply speeds in a list   z"Need to supply 3 body-fixed speedsz$Need to supply coordinates in a list)bodyspacez Not an acceptable rotation orderz$Need 3 coordinates for body or spacer   c                 S      g | ]}t |tjqS r,   r   r%   rO   r0   ir,   r,   r-   r2   "      z'kinematic_equations.<locals>.<listcomp>rh   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   ri   
quaternionrU   z)Cannot have rotation order for quaternion   z!Need 4 coordinates for quaternionc                 S   rj   r,   rk   rl   r,   r,   r-   r2   {  rn   g      ?z/Not an approved rotation type for this functionN)r   strlowerr'   listtupler(   lenrP   r
   Zeror   r   r   T)speedscoordsrot_type	rot_orderapproved_ordersw1w2w3q1q2q3q1dq2dq3ds1s2s3c1c2c3e0e1e2e3wEedotsr,   r,   r-   r"      s  #

"

" " 
$
"
"
"
"
$
" 
"
"
$

"
"
"
$
"
$
"
"
$
"
"
""

r"   c           
      K   s<  dd }t |  d|v rd}n	d|v rd}nd}g d}t|D ],\}}||vr9|d	k r3td||< q tj||< q |d	k rDt||  q t|| ||< q |dkrx||d |d tj|d
 | d }|||d tj|d | d }|d ||fS |dkr||d |d tj|d | S t	|d | }t	|| }	|	||d fS )a	  
    Returns the three motion parameters - (acceleration, velocity, and
    position) as vectorial functions of time in the given frame.

    If a higher order differential function is provided, the lower order
    functions are used as boundary conditions. For example, given the
    acceleration, the velocity and position parameters are taken as
    boundary conditions.

    The values of time at which the boundary conditions are specified
    are taken from timevalue1(for position boundary condition) and
    timevalue2(for velocity boundary condition).

    If any of the boundary conditions are not provided, they are taken
    to be zero by default (zero vectors, in case of vectorial inputs). If
    the boundary conditions are also functions of time, they are converted
    to constants by substituting the time values in the dynamicsymbols._t
    time Symbol.

    This function can also be used for calculating rotational motion
    parameters. Have a look at the Parameters and Examples for more clarity.

    Parameters
    ==========

    frame : ReferenceFrame
        The frame to express the motion parameters in

    acceleration : Vector
        Acceleration of the object/frame as a function of time

    velocity : Vector
        Velocity as function of time or as boundary condition
        of velocity at time = timevalue1

    position : Vector
        Velocity as function of time or as boundary condition
        of velocity at time = timevalue1

    timevalue1 : sympyfiable
        Value of time for position boundary condition

    timevalue2 : sympyfiable
        Value of time for velocity boundary condition

    Examples
    ========

    >>> from sympy.physics.vector import ReferenceFrame, get_motion_params, dynamicsymbols
    >>> from sympy.physics.vector import init_vprinting
    >>> init_vprinting(pretty_print=False)
    >>> from sympy import symbols
    >>> R = ReferenceFrame('R')
    >>> v1, v2, v3 = dynamicsymbols('v1 v2 v3')
    >>> v = v1*R.x + v2*R.y + v3*R.z
    >>> get_motion_params(R, position = v)
    (v1''*R.x + v2''*R.y + v3''*R.z, v1'*R.x + v2'*R.y + v3'*R.z, v1*R.x + v2*R.y + v3*R.z)
    >>> a, b, c = symbols('a b c')
    >>> v = a*R.x + b*R.y + c*R.z
    >>> get_motion_params(R, velocity = v)
    (0, a*R.x + b*R.y + c*R.z, a*t*R.x + b*t*R.y + c*t*R.z)
    >>> parameters = get_motion_params(R, acceleration = v)
    >>> parameters[1]
    a*t*R.x + b*t*R.y + c*t*R.z
    >>> parameters[2]
    a*t**2/2*R.x + b*t**2/2*R.y + c*t**2/2*R.z

    c                 S   s   |dkrt ||dd}| tdkrdd|fS t | |}t| |}td}|||f}|D ]}	||	}
|	|||i}|t|
|| |	 7 }q+|| |fS )a  
        Helper function for get_motion methods. Finds derivative of vectdiff
        wrt variable, and its integral using the specified boundary condition
        at value of variable = ordinate.
        Returns a tuple of - (derivative, function and integral) wrt vectdiff

        r   Tr7   )r   r   r    r   r=   r   )vectdiff	conditionvariableordinaterC   	vectdiff1	vectdiff2	vectdiff0limsdim	function1abscissar,   r,   r-   _process_vector_differential  s   





z7get_motion_params.<locals>._process_vector_differentialaccelerationr9   velocityr   r   )r   r   position	timevalue
timevalue1
timevalue2rg   r   r   r   )
r   	enumerater   r
   rv   r   r   r%   rO   r    )
rC   kwargsr   mode
conditionsrm   r1   velposaccr,   r,   r-   r#     sP   F 

r#   c                 C   s   t | stdt |stdg }t|}| D ]E}dd |D }|jD ]3\}}t||\}}	tt|D ]!}
t|D ]\}}|||
f dkrU||
  ||||
f  7  < q;q5q$|| q|S )a  Returns a list of partial velocities with respect to the provided
    generalized speeds in the given reference frame for each of the supplied
    velocity vectors.

    The output is a list of lists. The outer list has a number of elements
    equal to the number of supplied velocity vectors. The inner lists are, for
    each velocity vector, the partial derivatives of that velocity vector with
    respect to the generalized speeds supplied.

    Parameters
    ==========

    vel_vecs : iterable
        An iterable of velocity vectors (angular or linear).
    gen_speeds : iterable
        An iterable of generalized speeds.
    frame : ReferenceFrame
        The reference frame that the partial derivatives are going to be taken
        in.

    Examples
    ========

    >>> from sympy.physics.vector import Point, ReferenceFrame
    >>> from sympy.physics.vector import dynamicsymbols
    >>> from sympy.physics.vector import partial_velocity
    >>> u = dynamicsymbols('u')
    >>> N = ReferenceFrame('N')
    >>> P = Point('P')
    >>> P.set_vel(N, u * N.x)
    >>> vel_vecs = [P.vel(N)]
    >>> gen_speeds = [u]
    >>> partial_velocity(vel_vecs, gen_speeds, N)
    [[N.x]]

    z2Velocity vectors must be contained in an iterable.z3Generalized speeds must be contained in an iterablec                 S   s   g | ]}t d qS r   )r   )r0   _r,   r,   r-   r2   B  r3   z$partial_velocity.<locals>.<listcomp>r   )	r   r(   rs   r:   r   rangeru   r   append)vel_vecs
gen_speedsrC   vec_partialsr   partials
componentsrefmatr   rm   r   	directionr,   r,   r-   r$     s&   &r$   c                    sP   t | fdti|}tjt|r fdd|D }|S ttg  |S )a  Uses symbols and Function for functions of time.

    Creates a SymPy UndefinedFunction, which is then initialized as a function
    of a variable, the default being Symbol('t').

    Parameters
    ==========

    names : str
        Names of the dynamic symbols you want to create; works the same way as
        inputs to symbols
    level : int
        Level of differentiation of the returned function; d/dt once of t,
        twice of t, etc.
    assumptions :
        - real(bool) : This is used to set the dynamicsymbol as real,
                    by default is False.
        - positive(bool) : This is used to set the dynamicsymbol as positive,
                    by default is False.
        - commutative(bool) : This is used to set the commutative property of
                    a dynamicsymbol, by default is True.
        - integer(bool) : This is used to set the dynamicsymbol as integer,
                    by default is False.

    Examples
    ========

    >>> from sympy.physics.vector import dynamicsymbols
    >>> from sympy import diff, Symbol
    >>> q1 = dynamicsymbols('q1')
    >>> q1
    q1(t)
    >>> q2 = dynamicsymbols('q2', real=True)
    >>> q2.is_real
    True
    >>> q3 = dynamicsymbols('q3', positive=True)
    >>> q3.is_positive
    True
    >>> q4, q5 = dynamicsymbols('q4,q5', commutative=False)
    >>> bool(q4*q5 != q5*q4)
    True
    >>> q6 = dynamicsymbols('q6', integer=True)
    >>> q6.is_integer
    True
    >>> diff(q1, Symbol('t'))
    Derivative(q1(t), t)

    clsc                    s"   g | ]}t tg  |qS r,   )r   r   )r0   elevelrS   r,   r-   r2     s   " z"dynamicsymbols.<locals>.<listcomp>)r   r	   r%   rO   r   r   r   )namesr   assumptionsessesr,   r   r-   r%   O  s   1r%   rS   ')NF)r   )rU   r   )0	functoolsr   sympyr   r   r   r   r   r   r	   r
   r   r   sympy.integrals.integralsr   sympy.simplify.trigsimpr   vectorr   r   rC   r   r   dyadicr   printingr   r   r   r   r   sympy.utilities.iterablesr   sympy.utilities.miscr   __all__r   __doc__r   r   r    r!   r"   r#   r$   r%   rO   _strr,   r,   r,   r-   <module>   s6    0

gP
  
<
:
