K i`ddlmZddlmZmZmZmZmZmZm Z m Z m Z m Z ddl mZddlmZddlmZmZddlmZmZddlmZdd lmZmZmZmZmZdd lm Z dd l!m"Z"gd Z#d Z$e$xjJejHjJz c_%dZ&e&xjJejLjJz c_%ddZ'ddZ(dZ)e)xjJejRjJz c_%ddZ*dZ+dZ,ddZ-e de-_.de-_/y))reduce) sympifydiffsincosMatrixsymbolsFunctionSSymbollinear_eq_to_matrix) integratetrigsimp)Vector _check_vector) CoordinateSym _check_frame)Dyadic)vprintvsprintvpprintvlatexinit_vprinting)iterable) translate)crossdotexpresstime_derivativeouterkinematic_equationsget_motion_paramspartial_velocitydynamicsymbolsrrrrrcNt|ttfs td||z S)z7Cross product convenience wrapper for Vector.cross(): z$Cross product is between two vectors isinstancerr TypeErrorvec1vec2s d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/physics/vector/functions.pyrrs' dVV, ->?? $;cNt|ttfs td||zS)z3Dot product convenience wrapper for Vector.dot(): z"Dot product is between two vectorsr(r+s r.rrs' dVV, -<== $;r/Nc 0t||dk(r|St|tr|rV|jDcgc]}|d }}i}|D]"}|j |j |$|j |}tg}|jD]g} | d|k7rN|j| d| dz} tjr| jd} |t| |fgz }Y|t| gz }i|St|tre||}t|td} |jD]:} | t| d||t| d||t| d||zzz } <| S|rt} t|}|jD]>}t|ts|j |k7s$| j#|j @i}| D]"}|j |j |$|j |S|Scc}w)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) rrct|dS)Nfu)methodr)xs r.zexpress..ms*21T*Br/ variables)rr)rargsupdate variable_mapsubsdcmsimp applyfuncrr setr free_symbolsrframeadd) exprrDframe2r9r6 frame_list subs_dictfoutvecvtempol frame_sets r.r r (s` qy $ *.3A!B%3J3I 8  !67 899Y'D &Atu}yy11-;;>>+CDD&4-11&!+% & $ >FV AY ?A '!A$;1Q4)<1Q49=>? ?B ?  I4=D&& +a/AGGu4DMM!''* +I 8  !67 899Y' ' U4s HcHtj}t||dk(r|S|dzdk7s|dkr tdt |t rg}|j D]y}|d|k(r'|t|d|dj||fgz }2|tt |g|d|dj|t |gz zj z }{t |}t|||dz St |trtd}|j D]a}||dj||d|dzzz }||dt|d||dzzz }||d|dt|d|zzz }ct|||dz Stt||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) rrz"Unsupported value of order enteredTr8r:) r&_tr ValueErrorr)rr;r rr! ang_vel_inr)rFrDordertoutlistrLrKrNs r.r!r!s` A z  qyA~=>>$ IAtu}WQqT5DAFFqI"$%%OFA3K1>qT__U3faSkACDHDI  Ivueai88$ AY AA 1Q499Q<1Q4!A$;/ 0B 1Q4?1Q47!A$>? @B 1Q41Q4/!A$">>? @B Ar5%!)44GD%48!UCCr/cZt|ts td|j|S)z6Outer product convenience wrapper for Vector.outer(): z$Outer product is between two Vectors)r)rr*r"r+s r.r"r"s' dF #>?? ::d r/c d}tt|dd}|j}t|tt fs t dt|dk7r t dt|tt fs t d|dvrZ||vr td t|dk7r td |\}}}||cxk(r |cxk(rd k(rnntjgdzS|\}} } |D cgc]} t| tjc} \} } }t|t| t| g\}}}t|t| t| g\}}}|d k(r|d k(r6| ||z||zz |z z | ||zz ||zz || |z||zz|z|z z |z gS|dk(r6| ||z||zz |z z | ||zz ||zz ||z | |z||zz|z|z z gS|dk(r6| | |z||zz|z z | ||zz ||zz |||z||zz |z|z z |z gS|dk(r5| ||z||zz|z z | ||zz||zz |||z||zz|z|z z |z gS|dk(r5| ||z||zz|z z | ||zz ||zz|||z||zz|z|z z |z gS|dk(r5| ||z||zz|z z | ||zz ||zz||z ||z||zz|z|z z gS|dk(r5| ||z||zz|z z | ||zz ||zz||z ||z||zz|z|z zgS|dk(r6| | |z||zz|z z | ||zz ||zz ||z ||z||zz |z|z z gS|dk(r6| ||z||zz |z z | ||zz ||zz || |z||zz|z|z z |z gS|dk(r5| ||z||zz|z z | ||zz||zz |||z||zz|z|z z|z gS|dk(r5| ||z||zz|z z | ||zz ||zz|||z||zz|z|z z|z gS|dk(r6| | |z||zz|z z | ||zz ||zz |||z||zz |z|z z |z gS|dk(r|d k(r5| |z ||z||zz|z|z z | ||zz ||zz|||z||zz|z z gS|dk(r5| ||z||zz|z|z z |z | ||zz||zz |||z||zz|z z gS|dk(r5| ||z||zz|z|z z |z | ||zz ||zz|||z||zz|z z gS|dk(r6| |z | |z||zz|z|z z | ||zz ||zz |||z||zz |z z gS|dk(r6| ||z||zz |z|z z |z | ||zz ||zz || |z||zz|z z gS|dk(r6| | |z||zz|z|z z |z | ||zz ||zz |||z||zz |z z gS|dk(r5| |z ||z||zz|z|z z| ||zz ||zz|||z||zz|z z gS|dk(r6| |z ||z||zz |z|z z | ||zz ||zz || |z||zz|z z gS|dk(r6| | |z||zz|z|z z |z | ||zz ||zz |||z||zz |z z gS|dk(r5| ||z||zz|z|z z|z | ||zz||zz |||z||zz|z z gS|dk(r5| ||z||zz|z|z z|z | ||zz ||zz|||z||zz|z z gS|dk(r6| ||z||zz |z|z z |z | ||zz ||zz || |z||zz|z z gSy!y!|dk(r|dk7r tdt|dk7r td|\}}}}t!|d gz}t!|| ||g||| |g| |||g| | | |gg}t!||||fD cgc]} t| tjc} }t |j"d|j"z|j"zz Std cc} wcc} w)"aGives 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'] )123231312132213321121131212232313323123XYZxyz123123zNeed to supply speeds in a listz"Need to supply 3 body-fixed speedsz$Need to supply coordinates in a list)bodyspacez Not an acceptable rotation orderz$Need 3 coordinates for body or spacerrlrYrZr[r\r]r^r_r`rarbrcrdrm quaternionrhz)Cannot have rotation order for quaternionz!Need 4 coordinates for quaterniong?z/Not an approved rotation type for this functionN)rstrlowerr)listtupler*lenrRr Zerorr&rQrrrT)speedscoordsrot_type rot_orderapproved_ordersw1w2w3q1q2q3iq1dq2dq3ds1s2s3c1c2c3e0e1e2e3wEedotss r.r#r#s FFO#i.(H=I~~H ftUm ,9:: 6{a<== ftUm ,>??$$ O +?@ @ v;! CD D B  r Q FF8A:  B=CDa!2!23D S#"gs2wB0 B"gs2wB0 B v E!rBwb0B66b2g I9B38b2g#5";b"@@2EGGE!rBwb0B66b2g I9"H"r BG(;r'AB'FFHHE!sRx"r'1R77rBwJ:27R"W#4":R"??"DFFE!rBwb0B66b2g I927R"W#4":R"??"DFFE!rBwb0B66b2g I927R"W#4":R"??"DFFE!rBwb0B66b2g I9"HR"r'(9R'?"'DDFFE!rBwb0B66b2g I9"HR"r'(9R'?"'DDFFE!sRx"r'1R77rBwJ:"HR"r'(9R'?"'DDFFE!rBwb0B66b2g I9B38b2g#5";b"@@2EGGE!rBwb0B66b2g I927R"W#4":R"??"DFFE!rBwb0B66b2g I927R"W#4":R"??"DFFE!sRx"r'1R77rBwJ:27R"W#4":R"??"DFF w E!bBGb2g$5#;b#@@#IC"WC%&)R"WrBw->",D&DFFE!rBwb0B6;;b@#IC"WC%&)R"WrBw->",D&DFFE!rBwb0B6;;b@#IC"WC%&)R"WrBw->",D&DFFE!bRC"HrBw$6"#",D&DFFE!rBwb0B6;;b@#IC"WC%&)bS2XR-?2,E&EGGE!sRx"r'1R7"<",D&DFFE!bBGb2g$5#;b#@@#IC"WC%&)R"WrBw->",D&DFFE!bBGb2g$5#;b#@@#IC"WC%&)bS2XR-?2,E&EGGE!sRx"r'1R7"<",D&DFFE!rBwb0B6;;b@#IC"WC%&)R"WrBw->",D&DFFE!rBwb0B6;;b@#IC"WC%&)R"WrBw->",D&DFFE!rBwb0B6;;b@#IC"WC%&)bS2XR-?2,E&EGG"E J \ ! ?HI I v;! @A ABB 6QC<  R"b"%bS"%S"b"%S2#sB') *RR!_c Pd}t|d|vrd}n d|vrd}nd}gd}t|D]V\}}||vr(|dkrtd||<tj||<2|dkrt ||Ft ||||<X|dk(rQ||d|dtj|d |d}|||d tj|d |d}|d||fS|dk(r#||d|d tj|d |St|d |}t||} | ||d fS) 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 cF|dk7rt||d}|tdk(rdd|fSt||}t||}td}|||f}|D]J} |j| } | j|j ||i} |t | || z| zz }L|||fS)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 rTr8)r rr!rr>r) vectdiff conditionvariableordinaterD vectdiff1 vectdiff2 vectdiff0limsdim function1abscissas r._process_vector_differentialz7get_motion_params.._process_vector_differentials > 5DAI vay q)$ $He, #He4 1I (H- GC! c*Iwwy)..(/CDH )It4x?3F FI  G8Y//r/ accelerationr:velocityrr)rrposition timevalue timevalue1 timevalue2rkrrr) r enumeraterr rurrr&rQr!) rDkwargsrmode conditionsrr6velposaccs r.r$r$sL0@ v  ;J*% +1 F?1u"1Iq FFq U &) $q *F1I + qy*6.+A+1*+=+9+<+<+1,+?HIJK+3z0B+9+<+<+1,+?HHIK~&S11 +F:,>,2:,>,:,=,=,2<,@%I I fZ0%8c5)S&,--r/c t|s tdt|s tdg}t|}|D]}|Dcgc] }td}}|jD]`\}}t ||\} }t t|D]5} t|D]%\} } | | | fdk7s|| xx| | | | fzz cc<'7b|j||Scc}w)aReturns 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 iterabler) rr*rrrr;r rangertrappend) vel_vecs gen_speedsrD vec_partialsr_partials componentsrefmatrr directions r.r%r%sL H LMM J MNNLj!J &'12!F1I22"xx ?OJ(Z@FC3z?+ ?&/n?NC36{a'  y3sAv;'>> ? ? ? H% & 3sCc t|fdti|}tj}t |r*|Dcgc]}t t |g|z||}}|St t |g|z||Scc}w)aUses 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) cls)r r r&rQrrr)nameslevel assumptionsessesrUes r.r&r&Osub E 7x 7; 7EA:?@QqcEk1Q40@@ dQC%Kq22As"A3rU')NF)r)rh)r)0 functoolsrsympyrrrrrr r r r r sympy.integrals.integralsrsympy.simplify.trigsimprvectorrrrDrrdyadicrprintingrrrrrsympy.utilities.iterablesrsympy.utilities.miscr__all__r__doc__rr r!r"r#r$r%r&rQ_strr/r.rsJJJ/,).FF.*   %%%  vzz!!! dNMD` %%% ULpO.d9x73t3Kr/