diff --git a/role/_GoToPoint_.py b/role/_GoToPoint_.py index 2b815b1d..68308d10 100644 --- a/role/_GoToPoint_.py +++ b/role/_GoToPoint_.py @@ -42,7 +42,7 @@ def init(_kub,target,theta): global kub,GOAL_POINT,rotate,FLAG_turn,FLAG_move,FIRST_CALL kub = _kub - GOAL_POINT = point_2d() + GOAL_POINT = Vector2D() rotate = theta GOAL_POINT.x = target.x GOAL_POINT.y = target.y diff --git a/utils/math_functions.py b/utils/math_functions.py index 9b3ebf48..3d72dd1e 100644 --- a/utils/math_functions.py +++ b/utils/math_functions.py @@ -105,6 +105,7 @@ def intersection_with_line(self, line2): try: P.x = (c2 - c1) / (m1 - m2) P.y = (m1 * c2 - m2 * c1) / (m1 - m2) + return P except: return None return P @@ -166,7 +167,13 @@ def normalized_vector(self): # angle = math.atan(self.slope) angle = self.angle return Vector2D(math.cos(angle), math.sin(angle)) - + + def nearest_point_on_line(self,point): + t=(point.y-self.point.y)*math.sin(self.angle)+(point.x-self.point.x)*(math.cos(self.angle)) + x1=self.point.x+math.cos(self.angle)*t + y1=self.point.y+math.sin(self.angle)*t + point=Vector2D(x1,y1) + return point ## ## @var slope @@ -205,9 +212,9 @@ def direction(vector): return math.atan2(vector.y, vector.x) -def getPointBehindTheBall(point, theta): - x = point.x + (3.5 * BOT_RADIUS) * (math.cos(theta)) - y = point.y + (3.5 * BOT_RADIUS) * (math.sin(theta)) +def getPointBehindTheBall(point, theta, factor=3.5): + x = point.x + (factor * BOT_RADIUS) * (math.cos(theta)) + y = point.y + (factor * BOT_RADIUS) * (math.sin(theta)) return Vector2D(int(x), int(y)) def getPointToGo(point, theta): @@ -238,12 +245,6 @@ def stan_inverse(self,y,x): else: return atan2(y,x)+3.14159265 - -# def getPointBehindTheBall(point ,theta): -# x = point.x +(3.5 * BOT_RADIUS) *(math.cos(theta)) -# y = point.y +(3.5 * BOT_RADIUS) *(math.sin(theta)) -# return Vector2D(int(x), int(y)) - def vicinity_points(point1, point2, thresh=10): return dist(point1, point2) < thresh @@ -289,4 +290,4 @@ def kub_has_ball(state, kub_id): theta2 = math.atan2(state.ballPos.y - state.homePos[kub_id].y, state.ballPos.x - state.homePos[kub_id].x) return vicinity_theta(theta1, theta2, thresh=0.25) and vicinity_points(state.homePos[kub_id], - state.ballPos, thresh=BOT_RADIUS * 1.5) \ No newline at end of file + state.ballPos, thresh=BOT_RADIUS * 1.5) diff --git a/utils/state_functions.py b/utils/state_functions.py index 65898748..7a0afe16 100644 --- a/utils/state_functions.py +++ b/utils/state_functions.py @@ -37,7 +37,7 @@ def ball_moving_towards_our_goal(state): ptA = Vector2D(-HALF_FIELD_MAXX, DBOX_HEIGHT) ptB = Vector2D(-HALF_FIELD_MAXX, -DBOX_HEIGHT) defend_line = Line(point1=ptA,point2=ptB) - opponent_aim = Line.intersection_with_line(ball_movement) + opponent_aim = defend_line.intersection_with_line(ball_movement) if opponent_aim.y > -DBOX_HEIGHT and opponent_aim.y < DBOX_HEIGHT: return True return False @@ -84,7 +84,7 @@ def closest_opponent(state, position): def our_bot_closest_to_ball(state): distance_from_ball = 99999999 our_bot_closest_to_ball = 0 - for i in range(state.homePos.size()): + for i in range(len(state.homePos)): dist = math.sqrt(pow((state.homePos[i].x - state.ballPos.x),2) + pow((state.homePos[i].y - state.ballPos.y) , 2)) if dist < distance_from_ball : distance_from_ball = dist @@ -95,7 +95,7 @@ def our_bot_closest_to_ball(state): def opp_bot_closest_to_ball(state): distance_from_ball = 99999999 opp_bot_closest_to_ball = 0 - for i in range(state.awayPos.size()): + for i in range(len(state.awayPos)): dist = math.sqrt(pow((state.awayPos[i].x - state.ballPos.x),2) + pow((state.awayPos[i].y - state.ballPos.y) , 2)) if dist < distance_from_ball : distance_from_ball = dist