From 719e3c67ffa28e59acb4c8d47c0e07c5c3bb5572 Mon Sep 17 00:00:00 2001 From: kushal2000 <48222101+kushal2000@users.noreply.github.com> Date: Tue, 18 Jun 2019 03:03:11 +0530 Subject: [PATCH 1/9] point2d replaced with Vector2d in _init_ --- role/_GoToPoint_.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 3e00ec8c0b0a868af8f4bf954fcd62cad77b9882 Mon Sep 17 00:00:00 2001 From: sahil132jindal <43885654+sahil132jindal@users.noreply.github.com> Date: Tue, 18 Jun 2019 03:07:57 +0530 Subject: [PATCH 2/9] fixed a bug in ball_moving_towards_our_goal --- utils/state_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/state_functions.py b/utils/state_functions.py index 65898748..dc61734c 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 From 0bbcc60df69f472c1a7ad3e82daff1f4fe061d30 Mon Sep 17 00:00:00 2001 From: sahil132jindal <43885654+sahil132jindal@users.noreply.github.com> Date: Tue, 18 Jun 2019 03:10:09 +0530 Subject: [PATCH 3/9] fixed bug of return in line intersection --- utils/math_functions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/math_functions.py b/utils/math_functions.py index 5a7a553b..babd9ffc 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 ## @@ -288,4 +289,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) From 8914ab1ce44348a34c38be45f0328b0aea51bcaf Mon Sep 17 00:00:00 2001 From: kushal2000 <48222101+kushal2000@users.noreply.github.com> Date: Sun, 23 Jun 2019 21:13:32 +0530 Subject: [PATCH 4/9] Added nearest_point_on_line function to Line class --- utils/math_functions.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils/math_functions.py b/utils/math_functions.py index babd9ffc..edd415ad 100644 --- a/utils/math_functions.py +++ b/utils/math_functions.py @@ -166,7 +166,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)*self.angle+point.x-self.point.x)/(math.cos(self.angle)+math.sin(self.angle)*math.tan(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 From bda6911c0380762930759be8b621b2d81a41ca18 Mon Sep 17 00:00:00 2001 From: kushal2000 <48222101+kushal2000@users.noreply.github.com> Date: Sun, 23 Jun 2019 21:45:37 +0530 Subject: [PATCH 5/9] Correction made to nearest_point_on_line in Line class --- utils/math_functions.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/math_functions.py b/utils/math_functions.py index edd415ad..c8c20a46 100644 --- a/utils/math_functions.py +++ b/utils/math_functions.py @@ -168,7 +168,10 @@ def normalized_vector(self): return Vector2D(math.cos(angle), math.sin(angle)) def nearest_point_on_line(self,point): - t=((point.y-self.point.y)*self.angle+point.x-self.point.x)/(math.cos(self.angle)+math.sin(self.angle)*math.tan(self.angle)) + if math.cos(self.angle) == 0: + point = Vector2D(point.x,self.point.y) + return point + t=((point.y-self.point.y)*math.tan(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) From bf0d1ca09e9668626a35a88da8e2f808e6a2d280 Mon Sep 17 00:00:00 2001 From: kushal2000 Date: Mon, 24 Jun 2019 02:23:17 +0530 Subject: [PATCH 6/9] Simplified formula --- utils/math_functions.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/utils/math_functions.py b/utils/math_functions.py index c8c20a46..8236ffc0 100644 --- a/utils/math_functions.py +++ b/utils/math_functions.py @@ -168,10 +168,7 @@ def normalized_vector(self): return Vector2D(math.cos(angle), math.sin(angle)) def nearest_point_on_line(self,point): - if math.cos(self.angle) == 0: - point = Vector2D(point.x,self.point.y) - return point - t=((point.y-self.point.y)*math.tan(self.angle)+point.x-self.point.x)*(math.cos(self.angle)) + 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) From c460283ea5f890107ada0439e8beaa5250261675 Mon Sep 17 00:00:00 2001 From: Manjunath Bhat Date: Mon, 24 Jun 2019 22:08:34 +0530 Subject: [PATCH 7/9] Changed .size() to len() for homePos and awayPos awayPos and homePos have no attribute called size. So changed it to len(state.awayPos) and len(state.homePos) --- utils/state_functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/state_functions.py b/utils/state_functions.py index dc61734c..7a0afe16 100644 --- a/utils/state_functions.py +++ b/utils/state_functions.py @@ -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 From fa54e179cc864f9d4d16492a24ec98c3e0c217b3 Mon Sep 17 00:00:00 2001 From: Parth Mall Date: Tue, 25 Jun 2019 23:09:56 +0530 Subject: [PATCH 8/9] Made threshold in getPointBehindBall function variable --- utils/math_functions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/math_functions.py b/utils/math_functions.py index 8236ffc0..5b7d4b39 100644 --- a/utils/math_functions.py +++ b/utils/math_functions.py @@ -245,9 +245,9 @@ def stan_inverse(self,y,x): 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)) +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 vicinity_points(point1, point2, thresh=10): From 8e00ecafa2989f546639f5d3e498e701e9475839 Mon Sep 17 00:00:00 2001 From: Parth Mall Date: Tue, 25 Jun 2019 23:19:20 +0530 Subject: [PATCH 9/9] Removed the reduntant definition --- utils/math_functions.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/utils/math_functions.py b/utils/math_functions.py index 5b7d4b39..2a20bc01 100644 --- a/utils/math_functions.py +++ b/utils/math_functions.py @@ -211,9 +211,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): @@ -244,12 +244,6 @@ def stan_inverse(self,y,x): else: return atan2(y,x)+3.14159265 - -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 vicinity_points(point1, point2, thresh=10): return dist(point1, point2) < thresh