<s> __all__ = [ '<STR_LIT>' ] <EOL> import sys <EOL> if sys . version_info < ( <NUM_LIT:3> , <NUM_LIT:0> ) : <EOL> from collections import Iterator <EOL> else : <EOL> from collections . abc import Iterator <EOL> import numpy as np <EOL> from sympy import Dummy , lambdify <EOL> from sympy . matrices . expressions import Identity <EOL> from sympy . physics . mechanics import Point , ReferenceFrame <EOL> from . shapes import Shape <EOL> class VisualizationFrame ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( args [ - <NUM_LIT:1> ] , Shape ) : <EOL> self . _shape = args [ - <NUM_LIT:1> ] <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> i = <NUM_LIT:0> <EOL> if isinstance ( args [ i ] , str ) : <EOL> self . name = args [ i ] <EOL> i += <NUM_LIT:1> <EOL> else : <EOL> self . name = '<STR_LIT>' <EOL> try : <EOL> self . reference_frame = args [ i ] . get_frame ( ) <EOL> self . origin = args [ i ] . masscenter <EOL> except AttributeError : <EOL> try : <EOL> dcm = args [ i ] . _dcm_dict <EOL> self . reference_frame = args [ i ] <EOL> i += <NUM_LIT:1> <EOL> except AttributeError : <EOL> raise TypeError ( '''<STR_LIT>''' ) <EOL> try : <EOL> self . origin = args [ i ] . point <EOL> except AttributeError : <EOL> self . origin = args [ i ] <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' + self . name <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _name <EOL> @ name . setter <EOL> def name ( self , new_name ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( new_name , str ) : <EOL> raise TypeError ( '''<STR_LIT>''' ) <EOL> else : <EOL> self . _name = new_name <EOL> @ property <EOL> def origin ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _origin <EOL> @ origin . setter <EOL> def origin ( self , new_origin ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( new_origin , Point ) : <EOL> raise TypeError ( '''<STR_LIT>''' ) <EOL> else : <EOL> self . _origin = new_origin <EOL> @ property <EOL> def reference_frame ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _reference_frame <EOL> @ reference_frame . setter <EOL> def reference_frame ( self , new_reference_frame ) : <EOL> if not isinstance ( new_reference_frame , ReferenceFrame ) : <EOL> raise TypeError ( '''<STR_LIT>''' ) <EOL> else : <EOL> self . _reference_frame = new_reference_frame <EOL> @ property <EOL> def shape ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _shape <EOL> @ shape . setter <EOL> def shape ( self , new_shape ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( new_shape , Shape ) : <EOL> raise TypeError ( '''<STR_LIT>''' ) <EOL> else : <EOL> self . _shape = new_shape <EOL> def generate_transformation_matrix ( self , reference_frame , point ) : <EOL> """<STR_LIT>""" <EOL> rotation_matrix = self . reference_frame . dcm ( reference_frame ) <EOL> self . _transform = Identity ( <NUM_LIT:4> ) . as_mutable ( ) <EOL> self . _transform [ : <NUM_LIT:3> , : <NUM_LIT:3> ] = rotation_matrix <EOL> point_vector = self . origin . pos_from ( point ) <EOL> try : <EOL> self . _transform [ <NUM_LIT:3> , : <NUM_LIT:3> ] = point_vector . to_matrix ( reference_frame ) . T <EOL> except AttributeError : <EOL> self . _transform [ <NUM_LIT:3> , <NUM_LIT:0> ] = point_vector . dot ( reference_frame . x ) <EOL> self . _transform [ <NUM_LIT:3> , <NUM_LIT:1> ] = point_vector . dot ( reference_frame . y ) <EOL> self . _transform [ <NUM_LIT:3> , <NUM_LIT:2> ] = point_vector . dot ( reference_frame . z ) <EOL> return self . _transform <EOL> def generate_numeric_transform_function ( self , dynamic_variables , <EOL> constant_variables ) : <EOL> """<STR_LIT>""" <EOL> dummy_symbols = [ Dummy ( ) for i in dynamic_variables ] <EOL> dummy_dict = dict ( zip ( dynamic_variables , dummy_symbols ) ) <EOL> transform = self . _transform . subs ( dummy_dict ) . reshape ( <NUM_LIT:16> , <NUM_LIT:1> ) <EOL> dummy_symbols . extend ( constant_variables ) <EOL> self . _numeric_transform = [ ] <EOL> for i in range ( <NUM_LIT:16> ) : <EOL> t = transform [ i ] <EOL> if t . has ( Dummy ) : <EOL> f = lambdify ( dummy_symbols , t , modules = '<STR_LIT>' ) <EOL> else : <EOL> f = lambdify ( constant_variables , t , modules = '<STR_LIT>' ) <EOL> self . _numeric_transform . append ( f ) <EOL> return self . _numeric_transform <EOL> def evaluate_transformation_matrix ( self , dynamic_values , constant_values ) : <EOL> """<STR_LIT>""" <EOL> states = np . squeeze ( np . array ( dynamic_values ) ) <EOL> if not isinstance ( constant_values , Iterator ) : <EOL> constant_values = list ( constant_values ) <EOL> if len ( states . shape ) > <NUM_LIT:1> : <EOL> n = states . shape [ <NUM_LIT:0> ] <EOL> args = [ ] <EOL> for a in np . split ( states , states . shape [ <NUM_LIT:1> ] , <NUM_LIT:1> ) : <EOL> args . append ( np . squeeze ( a ) ) <EOL> for a in constant_values : <EOL> args . append ( np . repeat ( a , n ) ) <EOL> else : <EOL> n = <NUM_LIT:1> <EOL> args = np . hstack ( ( states , constant_values ) ) <EOL> new = np . zeros ( ( n , <NUM_LIT:16> ) ) <EOL> for i , t in enumerate ( self . _numeric_transform ) : <EOL> if callable ( t ) : <EOL> try : <EOL> new [ : , i ] = t ( * args ) <EOL> except TypeError : <EOL> new [ : , i ] = np . repeat ( t ( * constant_values ) , n ) <EOL> else : <EOL> new [ : , i ] = np . repeat ( t , n ) <EOL> self . _visualization_matrix = new . tolist ( ) <EOL> return self . _visualization_matrix <EOL> def generate_scene_dict ( self , constant_map = { } ) : <EOL> """<STR_LIT>""" <EOL> scene_dict = { id ( self ) : { } } <EOL> scene_dict [ id ( self ) ] = self . shape . generate_dict ( constant_map = constant_map ) <EOL> scene_dict [ id ( self ) ] [ '<STR_LIT:name>' ] = self . name <EOL> scene_dict [ id ( self ) ] [ "<STR_LIT>" ] = str ( self . reference_frame ) <EOL> scene_dict [ id ( self ) ] [ "<STR_LIT>" ] = id ( self ) <EOL> try : <EOL> scene_dict [ id ( self ) ] [ "<STR_LIT>" ] = self . _visualization_matrix [ <NUM_LIT:0> ] <EOL> except : <EOL> raise RuntimeError ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) <EOL> return scene_dict <EOL> def generate_simulation_dict ( self ) : <EOL> """<STR_LIT>""" <EOL> simulation_dict = { } <EOL> try : <EOL> simulation_dict [ id ( self ) ] = self . _visualization_matrix <EOL> except : <EOL> raise RuntimeError ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" ) <EOL> return simulation_dict </s>
