def connect(self, state, derivatives, mass): Variable.connect(self, state, derivatives, mass) self.state[0: 9] = self.rotation_matrix.ravel() self.rotation_matrix = numpy.reshape(self.state[0: 9], (3,3)) self.state[9: 12] = self.translation_vector self.translation_vector = self.state[9: 12] self.mass[0: 9] = self.inertia_tensor.ravel() self.inertia_tensor = numpy.reshape(self.mass[0: 9], (3,3)) self.mass[9: 12] = self.inertia_mass self.inertia_mass = self.mass[9: 12]
def create_all_possible_state_variables(symbols, static_symbols, type_map): """ Creates an index with all possible state variables """ variables = IndexDictionary() for symbol in symbols.values(): name = symbol.name if is_external( name ) or name in static_symbols: # The symbol won't yield any state variable continue instantiations = [type_map[t] for t in symbol.arguments] for instantiation in itertools.product(*instantiations): variables.add(Variable(symbol.name, instantiation)) return variables
def connect(self, state, derivatives, mass): Variable.connect(self, state, derivatives, mass) self.state[:] = self.translation_vector self.translation_vector = self.state self.mass[:] = self.inertia_mass self.inertia_mass = self.mass
def sanity_check(self): Variable.sanity_check(self) if self.translation_vector.shape != (3,): raise SanityError("The translation_vector must be a vector of length 3. The given array has shape=%s." % self.translation_vector.shape)
def __init__(self, rotation_matrix, translation_vector): Variable.__init__(self) self.rotation_matrix = rotation_matrix self.translation_vector = translation_vector self.inertia_mass = numpy.zeros(3, float)