|
@@ -39,23 +39,32 @@ def heuristic_fun(initparams, k, t=None):
|
|
|
t = initparams.goal
|
|
t = initparams.goal
|
|
|
return max([abs(t[0] - k[0]), abs(t[1] - k[1]), abs(t[2] - k[2])])
|
|
return max([abs(t[0] - k[0]), abs(t[1] - k[1]), abs(t[2] - k[2])])
|
|
|
|
|
|
|
|
-def isinbound(i, x, mode=False, factor = 0):
|
|
|
|
|
|
|
+def isinbound(i, x, mode = False, factor = 0, isarray = False):
|
|
|
if mode == 'obb':
|
|
if mode == 'obb':
|
|
|
- return isinobb(i, x)
|
|
|
|
|
- if i[0] - factor <= x[0] < i[3] + factor and i[1] - factor <= x[1] < i[4] + factor and i[2] - factor <= x[2] < i[5] + factor:
|
|
|
|
|
- return True
|
|
|
|
|
- return False
|
|
|
|
|
|
|
+ return isinobb(i, x, isarray)
|
|
|
|
|
+ if isarray:
|
|
|
|
|
+ compx = (i[0] - factor <= x[:,0]) & (x[:,0] < i[3] + factor)
|
|
|
|
|
+ compy = (i[1] - factor <= x[:,1]) & (x[:,0] < i[4] + factor)
|
|
|
|
|
+ compz = (i[2] - factor <= x[:,2]) & (x[:,0] < i[5] + factor)
|
|
|
|
|
+ return compx & compy & compz
|
|
|
|
|
+ else:
|
|
|
|
|
+ return i[0] - factor <= x[0] < i[3] + factor and i[1] - factor <= x[1] < i[4] + factor and i[2] - factor <= x[2] < i[5] + factor
|
|
|
|
|
|
|
|
def isinball(i, x, factor = 0):
|
|
def isinball(i, x, factor = 0):
|
|
|
if getDist(i[0:3], x) <= i[3] + factor:
|
|
if getDist(i[0:3], x) <= i[3] + factor:
|
|
|
return True
|
|
return True
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
-def isinobb(i, x):
|
|
|
|
|
|
|
+def isinobb(i, x, isarray = False):
|
|
|
# transform the point from {W} to {body}
|
|
# transform the point from {W} to {body}
|
|
|
- pt = i.T@np.append(x,1)
|
|
|
|
|
- block = [- i.E[0],- i.E[1],- i.E[2],+ i.E[0],+ i.E[1],+ i.E[2]]
|
|
|
|
|
- return isinbound(block, pt)
|
|
|
|
|
|
|
+ if isarray:
|
|
|
|
|
+ pts = (i.T@np.column_stack((x, np.ones(len(x)))).T).T[:,0:3]
|
|
|
|
|
+ block = [- i.E[0],- i.E[1],- i.E[2],+ i.E[0],+ i.E[1],+ i.E[2]]
|
|
|
|
|
+ return isinbound(block, pts, isarray = isarray)
|
|
|
|
|
+ else:
|
|
|
|
|
+ pt = i.T@np.append(x,1)
|
|
|
|
|
+ block = [- i.E[0],- i.E[1],- i.E[2],+ i.E[0],+ i.E[1],+ i.E[2]]
|
|
|
|
|
+ return isinbound(block, pt)
|
|
|
|
|
|
|
|
def OBB2AABB(obb):
|
|
def OBB2AABB(obb):
|
|
|
# https://www.gamasutra.com/view/feature/131790/simple_intersection_tests_for_games.php?print=1
|
|
# https://www.gamasutra.com/view/feature/131790/simple_intersection_tests_for_games.php?print=1
|
|
@@ -244,7 +253,6 @@ def StateSpace(env, factor=0):
|
|
|
Space.add((x, y, z))
|
|
Space.add((x, y, z))
|
|
|
return Space
|
|
return Space
|
|
|
|
|
|
|
|
-
|
|
|
|
|
def g_Space(initparams):
|
|
def g_Space(initparams):
|
|
|
'''This function is used to get nodes and discretize the space.
|
|
'''This function is used to get nodes and discretize the space.
|
|
|
State space is by x*y*z,3 where each 3 is a point in 3D.'''
|
|
State space is by x*y*z,3 where each 3 is a point in 3D.'''
|
|
@@ -254,7 +262,6 @@ def g_Space(initparams):
|
|
|
g[v] = np.inf # this hashmap initialize all g values at inf
|
|
g[v] = np.inf # this hashmap initialize all g values at inf
|
|
|
return g
|
|
return g
|
|
|
|
|
|
|
|
-
|
|
|
|
|
def isCollide(initparams, x, child, dist):
|
|
def isCollide(initparams, x, child, dist):
|
|
|
'''see if line intersects obstacle'''
|
|
'''see if line intersects obstacle'''
|
|
|
'''specified for expansion in A* 3D lookup table'''
|
|
'''specified for expansion in A* 3D lookup table'''
|
|
@@ -277,7 +284,6 @@ def isCollide(initparams, x, child, dist):
|
|
|
return True, dist
|
|
return True, dist
|
|
|
return False, dist
|
|
return False, dist
|
|
|
|
|
|
|
|
-
|
|
|
|
|
def children(initparams, x, settings = 0):
|
|
def children(initparams, x, settings = 0):
|
|
|
# get the neighbor of a specific state
|
|
# get the neighbor of a specific state
|
|
|
allchild = []
|
|
allchild = []
|
|
@@ -299,7 +305,6 @@ def children(initparams, x, settings = 0):
|
|
|
if settings == 1:
|
|
if settings == 1:
|
|
|
return allcost
|
|
return allcost
|
|
|
|
|
|
|
|
-
|
|
|
|
|
def obstacleFree(initparams, x):
|
|
def obstacleFree(initparams, x):
|
|
|
for i in initparams.env.blocks:
|
|
for i in initparams.env.blocks:
|
|
|
if isinbound(i, x):
|
|
if isinbound(i, x):
|
|
@@ -345,11 +350,9 @@ if __name__ == "__main__":
|
|
|
obb1 = obb([2.6,2.5,1],[0.2,2,2],R_matrix(0,0,45))
|
|
obb1 = obb([2.6,2.5,1],[0.2,2,2],R_matrix(0,0,45))
|
|
|
# obb2 = obb([1,1,0],[1,1,1],[[1/np.sqrt(3)*1,1/np.sqrt(3)*1,1/np.sqrt(3)*1],[np.sqrt(3/2)*(-1/3),np.sqrt(3/2)*2/3,np.sqrt(3/2)*(-1/3)],[np.sqrt(1/8)*(-2),0,np.sqrt(1/8)*2]])
|
|
# obb2 = obb([1,1,0],[1,1,1],[[1/np.sqrt(3)*1,1/np.sqrt(3)*1,1/np.sqrt(3)*1],[np.sqrt(3/2)*(-1/3),np.sqrt(3/2)*2/3,np.sqrt(3/2)*(-1/3)],[np.sqrt(1/8)*(-2),0,np.sqrt(1/8)*2]])
|
|
|
p0, p1 = [2.9,2.5,1],[1.9,2.5,1]
|
|
p0, p1 = [2.9,2.5,1],[1.9,2.5,1]
|
|
|
- dist = getDist(p0,p1)
|
|
|
|
|
|
|
+ pts = np.array([[1,2,3],[4,5,6],[7,8,9],[2,2,2],[1,1,1],[3,3,3]])
|
|
|
start = time.time()
|
|
start = time.time()
|
|
|
- for i in range(3000*27):
|
|
|
|
|
- lineAABB(p0,p1,dist,obb1)
|
|
|
|
|
- #lineOBB(p0,p1,dist,obb1)
|
|
|
|
|
|
|
+ isinbound(obb1, pts, mode='obb', factor = 0, isarray = True)
|
|
|
print(time.time() - start)
|
|
print(time.time() - start)
|
|
|
|
|
|
|
|
|
|
|