예제 #1
0
def circleIntersectRect2(c_center, c_radius, rect):
    # nearestX = max(rect.left, min(c_center[0], rect.left + rect.width));
    # nearestY = max(rect.top, min(c_center[1], rect.top + rect.height));

    nearestX = max(rect.left, min(c_center[0], rect.right))
    nearestY = max(rect.bottom, min(c_center[1], rect.top))

    return utils.distance2p(c_center, (nearestX, nearestY)) <= c_radius
예제 #2
0
 def random_tile_in_range(grid, start, radius):
     vis = []
     for x in range(start.x - radius, start.x + radius):
         for y in range(start.y - radius, start.y + radius):
             if not grid.out_of_bound(x, y):
                 t = grid.grid[x][y]
                 if t != start and utils.distance2p(
                     (start.x, start.y), (t.x, t.y)) < radius:
                     vis.append(t)
     return np.random.choice(vis)
예제 #3
0
 def random_tile_at_range(grid, start, radius, forbidden):
     vis = []
     for x in range(start.x - radius, start.x + radius):
         for y in range(start.y - radius, start.y + radius):
             if not grid.out_of_bound(x, y):
                 t = grid.grid[x][y]
                 if t != start and abs(
                         utils.distance2p((start.x, start.y),
                                          (t.x, t.y)) -
                         radius) < 1 and t.get_type() not in forbidden:
                     vis.append(t)
     if vis == []:
         return None
     return np.random.choice(vis)
예제 #4
0
def getPathLength(tile1,
                  tile2,
                  grid,
                  forbidden=[],
                  heur=heuristic_cost_estimate,
                  approx=False,
                  cost_dict=p.type2cost,
                  dn=False):
    if approx:
        res = utils.distance2p((tile1.x, tile1.y), (tile2.x, tile2.y))
    else:
        path = astar(tile1, tile2, grid, forbidden, heur, cost_dict, dn)
        res = computePathLength(path, cost_dict)
    return res
예제 #5
0
def getPathLength(tile1, tile2, maptiles=parameters.getInstance().MAP_TILES, forbidden=[], approx=False):
    if approx:
        res = utils.distance2p(tile1.getPose(), tile2.getPose())
    #OLD
    else:
        path = astar(tile1, tile2, maptiles, forbidden)
        res = computePathLength(path)
    
    return res
    

# def checkStraightPath(env, p1, p2, precision, check_obs=True, check_river=True):
#     #if line from entity.pos to target is OK, do not compute astar
#         #y = a*x + b => a==0 : parallele; a==inf : perpendicular; a == (-)1 : (-)45deg
#     a, b = geo.computeLineEquation(p1, p2)
#     astar_needed = False
#     if a == None or b == None:
#         astar_needed = True
#     elif abs(p1[0] - p2[0]) > abs(p1[1] - p2[1]):
#         mini = min(p1[0], p2[0])
#         maxi = max(p1[0], p2[0])

#         for step_x in range(int(mini), int(maxi), int(precision)):
#             y = a*step_x + b
#             if env.collideOneObstacle_Point((step_x, y), check_obs=check_obs, check_river=check_river):
#                 astar_needed = True
#     else:
#         mini = min(p1[1], p2[1])
#         maxi = max(p1[1], p2[1])

#         for step_y in range(int(mini), int(maxi), int(precision)):
#             # y = a*step_x + b
#             x = (step_y - b)/a
#             if env.collideOneObstacle_Point((x, step_y), check_obs=check_obs, check_river=check_river):
#                 astar_needed = True

#     return astar_needed
예제 #6
0
def heuristic_cost_estimate(_current, _goal):
    res = utils.distance2p((_current.x, _current.y), (_goal.x, _goal.y))
    # res = _goal.getCost()
    return res
예제 #7
0
def heuristic_cost_estimate(_current, _goal):
    res = utils.distance2p(_current.getPose(), _goal.getPose())
    # res = _goal.getCost()
    return res