Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
driving-simulation/simulation.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
59 lines (48 sloc)
2.44 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import numpy as np | |
class Simulation: | |
"This is the Simulation class. A simulation is a single run of the program with a set of parameters and arrays associated to those parameters." | |
#time variables | |
delta_time = 1 # time resolution/granularity of the simulation in seconds | |
number_of_frames = 0 #total frames the simulation goes through | |
simulation_resolution = 0 | |
#initial parameter values | |
init_alpha = 0 | |
init_delta_alpha = 0 | |
init_phi = 0 | |
# INITIALIZE X,Y LOC, SIZE, & COLOR ------------------------------------------------ | |
def __init__(self,delta_time,number_of_frames,init_alpha,init_delta_alpha,init_phi,simulation_resolution): | |
self.delta_time = delta_time | |
self.number_of_frames = number_of_frames | |
self.init_alpha = init_alpha | |
self.init_delta_alpha = init_delta_alpha | |
self.init_phi = init_phi | |
self.simulation_resolution = simulation_resolution | |
# FUNCTION TO GENERATE AND POPULATE A DICTIONARY BASED ON THE NUMBER OF FRAMES | |
# def update_nested_dictionary(frame,dict,list_of_vars,list_of_values): | |
# # create sub-dictionary for the frame | |
# dict_for_frame = {} | |
# # add sub-dictionary to the nested dictionary | |
# dict[frame] = dict_for_frame.fromkeys(list_of_vars) | |
# # iterate through list_of_values and add to the sub-dictionary (corresponding to each variable key) | |
# for i in range(0,len(list_of_values)): | |
# return(dict) | |
# USE THIS FUNCTION WHEN UPDATING ARRAYS, WRITE VARIABLE AND ARRAY IN PAIRS (VAR,ARRAY) | |
def append_arrays(*args): | |
for i in range(0,len(args)): | |
pair = args[i] | |
var = pair[0] | |
array = pair[1] | |
array.append(var) | |
def print_arrays(Simulation): | |
nearPoint_angles_inDegrees_array = np.array(list(map(math.degrees,Simulation.nearPoint_angle_array))) | |
farPoint_angle__inDegrees_array = np.array(list(map(math.degrees,Simulation.farPoint_angle_array))) | |
print( | |
"Agent position X,Y: ", Simulation.agent_x_position_array,Simulation.agent_y_position_array,"\n", | |
"nearPoint position X,Y: ",Simulation.nearPoint_x_array,Simulation.nearPoint_y_array,"\n", | |
"farPoint position X,Y: ", Simulation.farPoint_x_array,Simulation.farPoint_y_array,"\n", | |
"nearPoint angle, farPoint angle: ",nearPoint_angles_inDegrees_array, farPoint_angle__inDegrees_array,"\n", | |
"phi: ",Simulation.phi_array,"\n", | |
"alpha: ",Simulation.alpha_array,"\n", | |
"delta_alpha: ",Simulation.delta_alpha_array,"\n", | |
) |