In [9]:
import matplotlib.pyplot as plt
import Process as p
import numpy as np
import math as m
In [10]:
#define path
path = "C://Users//Ymubarak//Documents//ME102B//me102b_lane_painter//ImageProcessing//lines.txt"
In [11]:
# Make Image Object
Im = p.Image(path)
nodelist= Im.getNodes()
In [12]:
# seeing whole map shape
x1 = [n.xloc for n in nodelist]
x2 = [n.yloc for n in nodelist]
plt.scatter(x1,x2)
plt.show()
In [13]:
#testing the get neighbors function
random_node =0
nextnode = 1
n_size =4
n0 =nodelist[random_node]
ns = n0.findneighbors(nodelist,n_size)
x = [n.xloc for n in ns]
y = [n.yloc for n in ns]
plt.scatter(x,y)
plt.scatter(n0.xloc , n0.yloc)
#close= Im.NearestNode([n0.xloc, n0.yloc], nodelist)
#dist= close[1]
#closenode= close[0]
closenode = nodelist[nextnode]
plt.scatter(closenode.xloc, closenode.yloc)
plt.show()
p.getangle(n0, closenode)
Out[13]:
In [14]:
# #trying the least squares approach
# [n,error]=n0.gettangent(ns)
# n
# error
# ran = np.array(list(range(-2,2)))
# yhat = n[0]*ran
# plt.scatter(x,y)
# #plt.scatter(ran,yhat)
# plt.show()
# op_adj = n[0][0]
# m.atan(op_adj**-1) * 180/3.142
In [19]:
commands = Im.getNextStates(10)
p0 = [n0.xloc , n0.yloc]
for i in range(0,len(commands)):
theta = commands[i][0]
dist = commands[i][1]
pn = [dist*m.cos(theta) + p0[0], dist*m.sin(theta) + p0[1]]
if commands[i][2] :
plt.plot([p0[0], pn[0]],[p0[1], pn[1]] )
p0= pn
x1 = [n.xloc for n in nodelist]
x2 = [n.yloc for n in nodelist]
plt.scatter(x1,x2)
plt.show()
Out[19]:
In [23]:
x=np.array(commands)
Out[23]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: