<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> from sympy import simplify , solve , symbols <EOL> from sympy . physics . mechanics import ReferenceFrame , Point <EOL> from sympy . physics . mechanics import dot , dynamicsymbols <EOL> from util import msprint , partial_velocities , generalized_active_forces <EOL> q0 , q1 , q2 = dynamicsymbols ( '<STR_LIT>' ) <EOL> q0d , q1d , q2d = dynamicsymbols ( '<STR_LIT>' , level = <NUM_LIT:1> ) <EOL> u1 , u2 , u3 = dynamicsymbols ( '<STR_LIT>' ) <EOL> LA , LB , LP = symbols ( '<STR_LIT>' ) <EOL> p1 , p2 , p3 = symbols ( '<STR_LIT>' ) <EOL> g , mA , mB , mC , mD , t = symbols ( '<STR_LIT>' ) <EOL> E = ReferenceFrame ( '<STR_LIT:E>' ) <EOL> A = E . orientnew ( '<STR_LIT:A>' , '<STR_LIT>' , [ q0 , E . x ] ) <EOL> B = A . orientnew ( '<STR_LIT:B>' , '<STR_LIT>' , [ q1 , A . y ] ) <EOL> C = B . orientnew ( '<STR_LIT:C>' , '<STR_LIT>' , [ <NUM_LIT:0> , B . x ] ) <EOL> D = C . orientnew ( '<STR_LIT:D>' , '<STR_LIT>' , [ <NUM_LIT:0> , C . x ] ) <EOL> pO = Point ( '<STR_LIT:O>' ) <EOL> pA_star = pO . locatenew ( '<STR_LIT>' , LA * A . z ) <EOL> pP = pO . locatenew ( '<STR_LIT:P>' , LP * A . z ) <EOL> pB_star = pP . locatenew ( '<STR_LIT>' , LB * B . z ) <EOL> pC_star = pB_star . locatenew ( '<STR_LIT>' , q2 * B . z ) <EOL> pD_star = pC_star . locatenew ( '<STR_LIT>' , p1 * B . x + p2 * B . y + p3 * B . z ) <EOL> pO . set_vel ( E , <NUM_LIT:0> ) <EOL> pA_star . v2pt_theory ( pO , E , A ) <EOL> pP . v2pt_theory ( pO , E , A ) <EOL> pB_star . v2pt_theory ( pP , E , B ) <EOL> pC_star . set_vel ( B , pC_star . pos_from ( pB_star ) . diff ( t , B ) ) <EOL> pC_star . v1pt_theory ( pB_star , E , B ) <EOL> pD_star . set_vel ( B , pC_star . vel ( B ) ) <EOL> pD_star . v1pt_theory ( pB_star , E , B ) <EOL> pB_hat = pC_star . locatenew ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> pB_hat . v2pt_theory ( pP , E , B ) <EOL> kde = [ u1 - dot ( A . ang_vel_in ( E ) , A . x ) , <EOL> u2 - dot ( B . ang_vel_in ( A ) , B . y ) , <EOL> u3 - dot ( pC_star . vel ( B ) , B . z ) ] <EOL> kde_map = solve ( kde , [ q0d , q1d , q2d ] ) <EOL> def define_forces ( c , exert_by , exert_on , express ) : <EOL> return sum ( x * y <EOL> for x , y in zip ( symbols ( '<STR_LIT>' . format ( <EOL> c , exert_by , exert_on ) ) , <EOL> express ) ) <EOL> T_EA = define_forces ( '<STR_LIT:T>' , E , A , A ) <EOL> K_EA = define_forces ( '<STR_LIT>' , E , A , A ) <EOL> T_AB = define_forces ( '<STR_LIT:T>' , A , B , B ) <EOL> K_AB = define_forces ( '<STR_LIT>' , A , B , B ) <EOL> T_BC = define_forces ( '<STR_LIT:T>' , B , C , B ) <EOL> K_BC = define_forces ( '<STR_LIT>' , B , C , B ) <EOL> forces = [ ( pO , K_EA ) , ( pC_star , K_BC ) , ( pB_hat , - K_BC ) , <EOL> ( pA_star , - mA * g * E . x ) , ( pB_star , - mB * g * E . x ) , <EOL> ( pC_star , - mC * g * E . x ) , ( pD_star , - mD * g * E . x ) ] <EOL> torques = [ ( A , T_EA - T_AB ) , ( B , T_AB - T_BC ) , ( C , T_BC ) ] <EOL> partials = partial_velocities ( [ f [ <NUM_LIT:0> ] for f in forces + torques ] , <EOL> [ u1 , u2 , u3 ] , E , kde_map ) <EOL> Fr , _ = generalized_active_forces ( partials , forces + torques ) <EOL> print ( "<STR_LIT>" ) <EOL> for i , f in enumerate ( Fr , <NUM_LIT:1> ) : <EOL> print ( "<STR_LIT>" . format ( i , msprint ( simplify ( f ) ) ) ) </s>
