本文整理汇总了Python中Utils.Utils.distance_between方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.distance_between方法的具体用法?Python Utils.distance_between怎么用?Python Utils.distance_between使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utils.Utils
的用法示例。
在下文中一共展示了Utils.distance_between方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evaluate
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import distance_between [as 别名]
def evaluate(self, node):
score = 0
node.closest_lane_idx = self.lane.closest_sampled_idx(node.car.x, node.car.y)
# reward travaling along the lane in a certain direction
if node.prevNode is not None:
diff = node.closest_lane_idx - node.prevNode.closest_lane_idx
diff -= np.round(diff / self.lane.path_len) * self.lane.path_len
score += diff * -100
# reward smooth actions
score -= 50 * np.array(node.action_history).std()
# reward proximity to lane
distance = Utils.distance_between(
(self.lane.sampled_x[node.closest_lane_idx],self.lane.sampled_y[node.closest_lane_idx]),
(node.car.x, node.car.y))
score -= distance*distance * 10
# avoid collisions with other cars
for other_car in node.other_cars:
# detect if car comes from behind
normal = (-math.sin(node.car.theta),math.cos(node.car.theta))
diff = (other_car.x - node.car.x, other_car.y - node.car.y)
side = diff[0]*normal[0]+diff[1]*normal[1]
if side < -node.car.collision_radius()/2:
continue
# consider only the worst collision
worst_collision = None
# distance to car
dist = Utils.distance_between(
(other_car.x, other_car.y),
(node.car.x, node.car.y))
if dist < (node.car.collision_radius() + other_car.collision_radius()):
collision_score = -1e10
collision_score += dist*dist
if worst_collision is None or collision_score < worst_collision:
worst_collision = collision_score
if worst_collision is not None:
score = worst_collision
# f = 0.0
# score = f * np.array(node.heuristic_history).mean() + (1-f) * score
return score
示例2: on_mousemotion
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import distance_between [as 别名]
def on_mousemotion(self, event):
# highlight
self.highlight = None
for (x,y,k) in zip(self.support_x,self.support_y,range(self.n_support)):
if Utils.distance_between((x,y),event.pos) < self.highlight_radius:
self.highlight = k
# move support point
if self.selected is not None:
if time() - self.last_support_point_move > 1/60:
self.last_support_point_move = time()
self.interval = 5
self.move_support_point(self.selected, *event.pos)
示例3: update_distance_grid
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import distance_between [as 别名]
def update_distance_grid(self):
# return
if time() - self.last_distance_grid_update > 1 / 5:
self.last_distance_grid_update = time()
for i in range(self.grid.width):
for j in range(self.grid.height):
x,y = self.grid.xs[i], self.grid.ys[j]
closest_idx = self.lane.closest_sampled_idx(x, y)
distance = Utils.distance_between(
(self.lane.sampled_x[closest_idx],self.lane.sampled_y[closest_idx]),
(x,y))
# diff = np.array([self.lane.sampled_x[closest_idx]-x,self.lane.sampled_y[closest_idx]-y])
# distance = math.sqrt(np.sum(np.square(diff)))
self.grid.data[i,j] = distance*distance
示例4: on_mousebuttondown
# 需要导入模块: from Utils import Utils [as 别名]
# 或者: from Utils.Utils import distance_between [as 别名]
def on_mousebuttondown(self, event):
if event.button == 1: # left
# select support point
for (x,y,k) in zip(self.support_x,self.support_y,range(self.n_support)):
if Utils.distance_between((x,y),event.pos) < self.highlight_radius:
self.selected = k