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/distribute_points_along_curve.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
86 lines (62 sloc)
2.52 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 numpy as np | |
import replicate_Kountouriotis_et_al_2016 | |
import matplotlib.pyplot as plt | |
def interpcurve(N,pX,pY): | |
#equally spaced in arclength | |
N = np.transpose(np.linspace(0,1,N)) | |
#how many points will be uniformly interpolated? | |
nt=N.size | |
#number of points on the curve | |
n=pX.size | |
pxy=np.array((pX,pY)).T | |
p1=pxy[0,:] | |
pend=pxy[-1,:] | |
last_segment= np.linalg.norm(np.subtract(p1,pend)) | |
epsilon= 10*np.finfo(float).eps | |
#IF the two end points are not close enough lets close the curve | |
if last_segment > epsilon*np.linalg.norm(np.amax(abs(pxy),axis=0)): | |
pxy=np.vstack((pxy,p1)) | |
nt = nt + 1 | |
else: | |
print('Contour already closed') | |
pt=np.zeros((nt,2)) | |
#Compute the chordal arclength of each segment. | |
chordlen = (np.sum(np.diff(pxy,axis=0)**2,axis=1))**(1/2) | |
#Normalize the arclengths to a unit total | |
chordlen = chordlen/np.sum(chordlen) | |
#cumulative arclength | |
cumarc = np.append(0,np.cumsum(chordlen)) | |
tbins= np.digitize(N,cumarc) # bin index in which each N is in | |
#catch any problems at the ends | |
tbins[np.where(tbins<=0 | (N<=0))]=1 | |
tbins[np.where(tbins >= n | (N >= 1))] = n - 1 | |
s = np.divide((N - cumarc[tbins]),chordlen[tbins-1]) | |
pt = pxy[tbins,:] + np.multiply((pxy[tbins,:] - pxy[tbins-1,:]),(np.vstack([s]*2)).T) | |
return pt | |
center_X,center_Y = replicate_Kountouriotis_et_al_2016.center_x_array, replicate_Kountouriotis_et_al_2016.center_y_array | |
time_duration = 1 | |
perceived_x_center, perceived_y_center = replicate_Kountouriotis_et_al_2016.waypoint_fixation(13.8, time_duration, center_X, center_Y) | |
pt = interpcurve(10,perceived_x_center,perceived_y_center) | |
new_x_array = [] | |
new_y_array = [] | |
for i in range(0,10): | |
current_x = pt[i,0] | |
current_y = pt[i,1] | |
new_x_array.append(current_x) | |
new_y_array.append(current_y) | |
# for i in range(0,len(center_X)): | |
# current_center_x = center_X[i] | |
# current_center_y = center_Y[i] | |
# plt.plot(current_center_x,current_center_y, marker = "o",markerfacecolor="green" ) | |
for i in range(0,len(new_x_array)): | |
new_center_x = new_x_array[i] | |
new_center_y = new_y_array[i] | |
plt.plot(new_center_x,new_center_y, marker = "o",markerfacecolor="red" ) | |
for i in range(0,len(perceived_x_center)): | |
old_center_x = perceived_x_center[i] | |
old_center_y = perceived_y_center[i] | |
plt.plot(old_center_x,old_center_y, marker = "o",markerfacecolor="blue") | |
center_arc = plt.plot(center_X,center_Y,c='yellow',ls='--') | |
plt.show() | |
# def distribute_points(x,y): | |
# pt = interpcurve(N,x,y) |