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/plot_road_and_patches.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
100 lines (74 sloc)
5.61 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 matplotlib.pyplot as plt | |
import calculate_parallel_curves | |
import initialize_simulation | |
import replicate_Kountouriotis_et_al_2016 | |
# FUNCTION FOR GRAPHING/SETTING UP SIMULATION FEATURES ======================================== | |
def instantiate_simulation_patches(Agent): | |
agent_dot = plt.Circle((Agent.start_position_x,Agent.start_position_y), Agent.agent_size, fc =Agent.color,zorder = 10) | |
nearPoint = plt.Circle((Agent.start_position_x,Agent.start_position_y), 1, fc ='green',zorder = 9) | |
farPoint = plt.Circle((Agent.start_position_x,Agent.start_position_y), 1, fc ='blue',zorder = 8) | |
nearPoint_vector = plt.Line2D((Agent.start_position_x,Agent.start_position_y),(Agent.start_position_x,Agent.start_position_y), lw=2.5, color = 'green',zorder = 9) | |
farPoint_vector = plt.Line2D((Agent.start_position_x,Agent.start_position_y),(Agent.start_position_x,Agent.start_position_y), lw=2.5, color = 'blue',zorder = 8) | |
heading_vector = plt.Line2D((Agent.start_position_x,Agent.start_position_y),(Agent.start_position_x,Agent.start_position_y), lw=2.5, color = 'purple') | |
agent_trace = plt.Line2D((Agent.start_position_x,Agent.start_position_y),(Agent.start_position_x,Agent.start_position_y), lw=1, color = 'red') | |
return(agent_dot,nearPoint,farPoint,nearPoint_vector,farPoint_vector,heading_vector,agent_trace) | |
def instantiate_standard_road(ax1): | |
center_line = ax1.plot(calculate_parallel_curves.x,calculate_parallel_curves.final_sine,c='yellow',ls='--') | |
center_X = calculate_parallel_curves.x | |
center_Y = calculate_parallel_curves.final_sine | |
left, = ax1.plot(calculate_parallel_curves.left_x_array,calculate_parallel_curves.left_y_array, color = "black") | |
right, = ax1.plot(calculate_parallel_curves.right_x_array,calculate_parallel_curves.right_y_array, color = "black") | |
return(center_line,center_X,center_Y,left,right) | |
def instantiate_Kountouriotis2016_rep_road(ax1): | |
# Plot entire road to go under segmented lines (for continuity) | |
center_X = replicate_Kountouriotis_et_al_2016.center_x_array | |
center_Y = replicate_Kountouriotis_et_al_2016.center_y_array | |
#center_full_road = ax1.plot(center_X,center_Y, color = "black",ls='--') | |
outside_road = ax1.plot(replicate_Kountouriotis_et_al_2016.outside_x_array,replicate_Kountouriotis_et_al_2016.outside_y_array, color = "black") | |
inside_road = ax1.plot(replicate_Kountouriotis_et_al_2016.inside_x_array,replicate_Kountouriotis_et_al_2016.inside_y_array, color = "black") | |
full_road = outside_road,inside_road | |
center_road_x,center_road_y = replicate_Kountouriotis_et_al_2016.center_x_array_separate_parts,replicate_Kountouriotis_et_al_2016.center_y_array_seperat_parts | |
outside_road_x,outside_road_y= replicate_Kountouriotis_et_al_2016.outside_x_array_seperate_parts,replicate_Kountouriotis_et_al_2016.outside_y_array_separate_parts | |
inside_road_x,inside_road_y = replicate_Kountouriotis_et_al_2016.inside_x_array_separate_parts,replicate_Kountouriotis_et_al_2016.inside_y_array_separate_parts | |
# Plot center line | |
first_straight_line_center = ax1.plot(center_road_x[0], center_road_y[0],c='green',ls='--') | |
middle_curved_line_center = ax1.plot(center_road_x[1], center_road_y[1],c='black',ls='--') | |
last_straight_line_center = ax1.plot(center_road_x[2], center_road_y[2],c='green',ls='--') | |
# Plot outside line (left side) | |
first_straight_left_side = ax1.plot(outside_road_x[0],outside_road_y[0], color = "green") | |
middle_curved_left_side = ax1.plot(outside_road_x[1],outside_road_y[1], color = "black") | |
last_straight_left_side = ax1.plot(outside_road_x[2],outside_road_y[2], color = "green") | |
# Plot inside line (right side) | |
first_straight_right_side = ax1.plot(inside_road_x[0],inside_road_y[0], color = "green") | |
middle_curved_right_side = ax1.plot(inside_road_x[1],inside_road_y[1], color = "black") | |
last_straight_right_side = ax1.plot(inside_road_x[2],inside_road_y[2], color = "green") | |
# assign these to segnent variables (so there's less variables to return/reference) | |
first_road_segment = first_straight_left_side,first_straight_line_center,first_straight_right_side | |
middle_road_segment = middle_curved_left_side,middle_curved_line_center,middle_curved_right_side | |
last_road_segment = last_straight_left_side,last_straight_line_center,last_straight_right_side | |
return(center_X,center_Y,first_road_segment,middle_road_segment,last_road_segment,full_road) | |
# look at this later (to match/validate) | |
def set_vectors_xydata(nearPoint_vector,nearPoint_x,nearPoint_y, | |
farPoint_vector,farPoint_x,farPoint_y, | |
heading_vector, | |
currentAgent_x,currentAgent_y,prevAgent_x,prevAgent_y, | |
agent_trace_x,agent_trace_y,agent_trace): | |
delta_x = currentAgent_x - prevAgent_x | |
delta_y = currentAgent_y - prevAgent_y | |
nearPoint_vector.set_xdata([currentAgent_x,nearPoint_x]) | |
nearPoint_vector.set_ydata([currentAgent_y,nearPoint_y]) | |
farPoint_vector.set_xdata([currentAgent_x,farPoint_x]) | |
farPoint_vector.set_ydata([currentAgent_y, farPoint_y]) | |
heading_vector.set_xdata([prevAgent_x,currentAgent_x+delta_x*500]) | |
heading_vector.set_ydata([prevAgent_y,currentAgent_y+delta_y*500]) | |
agent_trace.set_xdata(agent_trace_x) | |
agent_trace.set_ydata(agent_trace_y) | |
def get_agent_trace(i,dictionary): | |
agent_trace_x = [] | |
agent_trace_y = [] | |
for sub_dictionary in range(0,i): | |
trace_x = dictionary[sub_dictionary]['agent_x_loc'] | |
trace_y = dictionary[sub_dictionary]['agent_y_loc'] | |
agent_trace_x.append(trace_x) | |
agent_trace_y.append(trace_y) | |
return(agent_trace_x,agent_trace_y) |