#NEWLINE# def test_coordinate_vars( ) : #NEWLINE# #INDENT# 'Tests the coordinate variables functionality' #NEWLINE# A = ReferenceFrame ( 'A' ) #NEWLINE# assert ( CoordinateSym ( 'Ax' , A , 0 ) == A [ 0 ] ) #NEWLINE# assert ( CoordinateSym ( 'Ax' , A , 1 ) == A [ 1 ] ) #NEWLINE# assert ( CoordinateSym ( 'Ax' , A , 2 ) == A [ 2 ] ) #NEWLINE# q = dynamicsymbols ( 'q' ) #NEWLINE# qd = dynamicsymbols ( 'q' , 1 ) #NEWLINE# assert ( isinstance ( A [ 0 ] , CoordinateSym ) and isinstance ( A [ 0 ] , CoordinateSym ) and isinstance ( A [ 0 ] , CoordinateSym ) ) #NEWLINE# assert ( A . variable_map ( A ) == { #NEWLINE# #INDENT# A [ 0 ] : A [ 0 ] , #NEWLINE# A [ 1 ] : A [ 1 ] , #NEWLINE# A [ 2 ] : A [ 2 ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( A [ 0 ] . frame == A ) #NEWLINE# B = A . orientnew ( 'B' , 'Axis' , [ q , A . z ] ) #NEWLINE# assert ( B . variable_map ( A ) == { #NEWLINE# #INDENT# B [ 2 ] : A [ 2 ] , #NEWLINE# B [ 1 ] : ( ( ( - A [ 0 ] ) * sin ( q ) ) + ( A [ 1 ] * cos ( q ) ) ) , #NEWLINE# B [ 0 ] : ( ( A [ 0 ] * cos ( q ) ) + ( A [ 1 ] * sin ( q ) ) ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( A . variable_map ( B ) == { #NEWLINE# #INDENT# A [ 0 ] : ( ( B [ 0 ] * cos ( q ) ) - ( B [ 1 ] * sin ( q ) ) ) , #NEWLINE# A [ 1 ] : ( ( B [ 0 ] * sin ( q ) ) + ( B [ 1 ] * cos ( q ) ) ) , #NEWLINE# A [ 2 ] : B [ 2 ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( time_derivative ( B [ 0 ] , A ) == ( ( ( ( - A [ 0 ] ) * sin ( q ) ) * qd ) + ( ( A [ 1 ] * cos ( q ) ) * qd ) ) ) #NEWLINE# assert ( time_derivative ( B [ 1 ] , A ) == ( ( ( ( - A [ 0 ] ) * cos ( q ) ) * qd ) - ( ( A [ 1 ] * sin ( q ) ) * qd ) ) ) #NEWLINE# assert ( time_derivative ( B [ 2 ] , A ) == 0 ) #NEWLINE# assert ( express ( B [ 0 ] , A , variables = True ) == ( ( A [ 0 ] * cos ( q ) ) + ( A [ 1 ] * sin ( q ) ) ) ) #NEWLINE# assert ( express ( B [ 1 ] , A , variables = True ) == ( ( ( - A [ 0 ] ) * sin ( q ) ) + ( A [ 1 ] * cos ( q ) ) ) ) #NEWLINE# assert ( express ( B [ 2 ] , A , variables = True ) == A [ 2 ] ) #NEWLINE# assert ( time_derivative ( ( ( ( A [ 0 ] * A . x ) + ( A [ 1 ] * A . y ) ) + ( A [ 2 ] * A . z ) ) , B ) == ( ( ( A [ 1 ] * qd ) * A . x ) - ( ( A [ 0 ] * qd ) * A . y ) ) ) #NEWLINE# assert ( time_derivative ( ( ( ( B [ 0 ] * B . x ) + ( B [ 1 ] * B . y ) ) + ( B [ 2 ] * B . z ) ) , A ) == ( ( ( ( - B [ 1 ] ) * qd ) * B . x ) + ( ( B [ 0 ] * qd ) * B . y ) ) ) #NEWLINE# assert ( express ( ( ( B [ 0 ] * B [ 1 ] ) * B [ 2 ] ) , A , variables = True ) == ( ( A [ 2 ] * ( ( ( - A [ 0 ] ) * sin ( q ) ) + ( A [ 1 ] * cos ( q ) ) ) ) * ( ( A [ 0 ] * cos ( q ) ) + ( A [ 1 ] * sin ( q ) ) ) ) ) #NEWLINE# assert ( ( time_derivative ( ( ( B [ 0 ] * B [ 1 ] ) * B [ 2 ] ) , A ) - ( ( A [ 2 ] * ( ( ( ( - ( A [ 0 ] ** 2 ) ) * cos ( ( 2 * q ) ) ) - ( ( ( 2 * A [ 0 ] ) * A [ 1 ] ) * sin ( ( 2 * q ) ) ) ) + ( ( A [ 1 ] ** 2 ) * cos ( ( 2 * q ) ) ) ) ) * qd ) ) . trigsimp ( ) == 0 ) #NEWLINE# assert ( express ( ( ( ( B [ 0 ] * B . x ) + ( B [ 1 ] * B . y ) ) + ( B [ 2 ] * B . z ) ) , A ) == ( ( ( ( ( B [ 0 ] * cos ( q ) ) - ( B [ 1 ] * sin ( q ) ) ) * A . x ) + ( ( ( B [ 0 ] * sin ( q ) ) + ( B [ 1 ] * cos ( q ) ) ) * A . y ) ) + ( B [ 2 ] * A . z ) ) ) #NEWLINE# assert ( express ( ( ( ( B [ 0 ] * B . x ) + ( B [ 1 ] * B . y ) ) + ( B [ 2 ] * B . z ) ) , A , variables = True ) == ( ( ( A [ 0 ] * A . x ) + ( A [ 1 ] * A . y ) ) + ( A [ 2 ] * A . z ) ) ) #NEWLINE# assert ( express ( ( ( ( A [ 0 ] * A . x ) + ( A [ 1 ] * A . y ) ) + ( A [ 2 ] * A . z ) ) , B ) == ( ( ( ( ( A [ 0 ] * cos ( q ) ) + ( A [ 1 ] * sin ( q ) ) ) * B . x ) + ( ( ( ( - A [ 0 ] ) * sin ( q ) ) + ( A [ 1 ] * cos ( q ) ) ) * B . y ) ) + ( A [ 2 ] * B . z ) ) ) #NEWLINE# assert ( express ( ( ( ( A [ 0 ] * A . x ) + ( A [ 1 ] * A . y ) ) + ( A [ 2 ] * A . z ) ) , B , variables = True ) == ( ( ( B [ 0 ] * B . x ) + ( B [ 1 ] * B . y ) ) + ( B [ 2 ] * B . z ) ) ) #NEWLINE# N = B . orientnew ( 'N' , 'Axis' , [ ( - q ) , B . z ] ) #NEWLINE# assert ( N . variable_map ( A ) == { #NEWLINE# #INDENT# N [ 0 ] : A [ 0 ] , #NEWLINE# N [ 2 ] : A [ 2 ] , #NEWLINE# N [ 1 ] : A [ 1 ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# C = A . orientnew ( 'C' , 'Axis' , [ q , ( ( A . x + A . y ) + A . z ) ] ) #NEWLINE# mapping = A . variable_map ( C ) #NEWLINE# assert ( mapping [ A [ 0 ] ] == ( ( ( ( ( ( ( ( 2 * C [ 0 ] ) * cos ( q ) ) / 3 ) + ( C [ 0 ] / 3 ) ) - ( ( ( 2 * C [ 1 ] ) * sin ( ( q + ( pi / 6 ) ) ) ) / 3 ) ) + ( C [ 1 ] / 3 ) ) - ( ( ( 2 * C [ 2 ] ) * cos ( ( q + ( pi / 3 ) ) ) ) / 3 ) ) + ( C [ 2 ] / 3 ) ) ) #NEWLINE# assert ( mapping [ A [ 1 ] ] == ( ( ( ( ( ( ( ( ( - 2 ) * C [ 0 ] ) * cos ( ( q + ( pi / 3 ) ) ) ) / 3 ) + ( C [ 0 ] / 3 ) ) + ( ( ( 2 * C [ 1 ] ) * cos ( q ) ) / 3 ) ) + ( C [ 1 ] / 3 ) ) - ( ( ( 2 * C [ 2 ] ) * sin ( ( q + ( pi / 6 ) ) ) ) / 3 ) ) + ( C [ 2 ] / 3 ) ) ) #NEWLINE# assert ( mapping [ A [ 2 ] ] == ( ( ( ( ( ( ( ( ( - 2 ) * C [ 0 ] ) * sin ( ( q + ( pi / 6 ) ) ) ) / 3 ) + ( C [ 0 ] / 3 ) ) - ( ( ( 2 * C [ 1 ] ) * cos ( ( q + ( pi / 3 ) ) ) ) / 3 ) ) + ( C [ 1 ] / 3 ) ) + ( ( ( 2 * qd [ 2 ] ) * cos ( q ) ) / 3 ) ) + ( C [ 2 ] / 3 ) ) )