@@ -105,6 +105,7 @@ def intersection_with_line(self, line2):
105105 try :
106106 P .x = (c2 - c1 ) / (m1 - m2 )
107107 P .y = (m1 * c2 - m2 * c1 ) / (m1 - m2 )
108+ return P
108109 except :
109110 return None
110111 return P
@@ -166,7 +167,13 @@ def normalized_vector(self):
166167 # angle = math.atan(self.slope)
167168 angle = self .angle
168169 return Vector2D (math .cos (angle ), math .sin (angle ))
169-
170+
171+ def nearest_point_on_line (self ,point ):
172+ t = (point .y - self .point .y )* math .sin (self .angle )+ (point .x - self .point .x )* (math .cos (self .angle ))
173+ x1 = self .point .x + math .cos (self .angle )* t
174+ y1 = self .point .y + math .sin (self .angle )* t
175+ point = Vector2D (x1 ,y1 )
176+ return point
170177
171178 ##
172179 ## @var slope
@@ -239,10 +246,10 @@ def stan_inverse(self,y,x):
239246 return atan2 (y ,x )+ 3.14159265
240247
241248
242- # def getPointBehindTheBall(point ,theta):
243- # x = point.x +(3.5 * BOT_RADIUS) *(math.cos(theta))
244- # y = point.y +(3.5 * BOT_RADIUS) *(math.sin(theta))
245- # return Vector2D(int(x), int(y))
249+ def getPointBehindTheBall (point ,theta , factor = 3.5 ):
250+ x = point .x + (factor * BOT_RADIUS ) * (math .cos (theta ))
251+ y = point .y + (factor * BOT_RADIUS ) * (math .sin (theta ))
252+ return Vector2D (int (x ), int (y ))
246253
247254def vicinity_points (point1 , point2 , thresh = 10 ):
248255 return dist (point1 , point2 ) < thresh
@@ -289,4 +296,4 @@ def kub_has_ball(state, kub_id):
289296 theta2 = math .atan2 (state .ballPos .y - state .homePos [kub_id ].y ,
290297 state .ballPos .x - state .homePos [kub_id ].x )
291298 return vicinity_theta (theta1 , theta2 , thresh = 0.25 ) and vicinity_points (state .homePos [kub_id ],
292- state .ballPos , thresh = BOT_RADIUS * 1.5 )
299+ state .ballPos , thresh = BOT_RADIUS * 1.5 )
0 commit comments