def closest_point_to_obstacle(point_test, polygon): ref_point = [] distance = INITIAL_DISTANCE_VALUE for n in range(len(polygon) + 1): ref_point.append(n % len(polygon)) # distance = list closest_point_on_obstacle = Point(0, 0) for n in range(len(polygon)): # line_temp = polygon[n].find_line_point_to_point(polygon[n + 1]) # distance.append(point_test, line_temp) point_obstacle = closest_point_to_line(point_test, polygon[ref_point[n]], polygon[ref_point[n + 1]]) if point_test.find_distance_between_points(point_obstacle) < distance: distance = point_test.find_distance_between_points(point_obstacle) closest_point_on_obstacle.x = point_obstacle.x closest_point_on_obstacle.y = point_obstacle.y return closest_point_on_obstacle
def closest_point_to_obstacle(point_test, polygon): ref_point = [] distance = INITIAL_DISTANCE_VALUE for n in range(polygon.get_length() + 1): ref_point.append(n % polygon.get_length()) closest_point_on_obstacle = Point(0, 0) for n in range(polygon.get_length()): # line_temp = polygon[n].find_line_point_to_point(polygon[n + 1]) # distance.append(point_test, line_temp) # print(ref_point[n], ref_point[n+1]) point_obstacle = closest_point_to_line(point_test, polygon.poly[ref_point[n]], polygon.poly[ref_point[n + 1]]) if point_test.find_distance_between_points(point_obstacle) < distance: distance = point_test.find_distance_between_points(point_obstacle) closest_point_on_obstacle.x = point_obstacle.x closest_point_on_obstacle.y = point_obstacle.y closest_point_on_obstacle.plot_point() return closest_point_on_obstacle