Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def growSimpleRRT(points):
- newPoints = {}
- adjListMap = {}
- bool = True
- count = 0
- # Your code goes here
- for i in points:
- if len(newPoints) == 0:
- newPoints[i] = points[i]
- newPoints[i+1] = points[i+1]
- adjListMap[i] = [i+1]
- adjListMap[i+1] = [i]
- elif len(newPoints) == 2 and bool:
- bool = False
- continue
- else:
- num = 0
- index = 0
- point1 = 0
- point2 = 0
- d = sys.maxsize #distance from random point to nearest point on line
- x = 0
- y = 0
- for j in list(adjListMap): # j is the key in adjListMap. j just goes through each point
- for k in adjListMap[j]: # k goes through every point that j is connected to
- m1 = (newPoints[k][1]-newPoints[j][1])/(newPoints[k][0]-newPoints[j][0])
- b1 = newPoints[j][1] - m1*newPoints[j][0]
- m2 = -1/m1
- b2 = points[i][1] - m2*points[i][0]
- newPointX = (b2-b1)/(m1-m2)
- newPointY = m1*newPointX + b1
- if not collisionDetection(adjListMap,newPoints,[points[i],(newPointX,newPointY)],j,k):
- if (newPoints[k][0] <= newPointX <= newPoints[j][0] or newPoints[k][0] >= newPointX >= newPoints[j][0]) and (newPoints[k][1] <= newPointY <= newPoints[j][1] or newPoints[k][1] >= newPointY >= newPoints[j][1]):
- if d > math.sqrt((newPointX-points[i][0])**2+(newPointY-points[i][1])**2):
- d = math.sqrt((newPointX-points[i][0])**2+(newPointY-points[i][1])**2)
- x = newPointX
- y = newPointY
- point1 = j
- point2 = k
- num = 0
- else:
- if newPoints[k][0] > newPoints[j][0]:
- if newPointX > newPoints[k][0]:
- if d > math.sqrt((newPoints[k][0]-points[i][0])**2+(newPoints[k][1]-points[i][1])**2):
- d = math.sqrt((newPoints[k][0]-points[i][0])**2+(newPoints[k][1]-points[i][1])**2)
- index = k
- num = 1
- else:
- if d > math.sqrt((newPoints[j][0]-points[i][0])**2+(newPoints[j][1]-points[i][1])**2):
- d = math.sqrt((newPoints[j][0]-points[i][0])**2+(newPoints[j][1]-points[i][1])**2)
- index = j
- num = 1
- else:
- if newPointX > newPoints[j][0]:
- if d > math.sqrt((newPoints[j][0]-points[i][0])**2+(newPoints[j][1]-points[i][1])**2):
- d = math.sqrt((newPoints[j][0]-points[i][0])**2+(newPoints[j][1]-points[i][1])**2)
- index = j
- num = 1
- else:
- if d > math.sqrt((newPoints[k][0]-points[i][0])**2+(newPoints[k][1]-points[i][1])**2):
- d = math.sqrt((newPoints[k][0]-points[i][0])**2+(newPoints[k][1]-points[i][1])**2)
- index = k
- num = 1
- if newPointX != points[i][0] and newPointY != points[i][1]:
- temp = i+count
- newPoints[temp] = points[i]
- if num == 0:
- count+=1
- newPoints[i+count] = (x,y)
- if adjListMap.get(temp) == None:
- adjListMap[temp] = [i+count]
- else:
- adjListMap[temp].append(i+count)
- adjListMap[i+count] = [temp]
- adjListMap[i+count].append(point1)
- adjListMap[i+count].append(point2)
- newList = adjListMap[point1]
- newList.remove(point2)
- newList.append(i+count)
- adjListMap[point1] = newList
- newList = adjListMap[point2]
- newList.remove(point1)
- newList.append(i+count)
- adjListMap[point2] = newList
- else:
- adjListMap[temp] = [index]
- adjListMap[index].append(temp)
- return newPoints, adjListMap
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement