@@ -105,6 +105,7 @@ def intersection_with_line(self, line2):
105
105
try :
106
106
P .x = (c2 - c1 ) / (m1 - m2 )
107
107
P .y = (m1 * c2 - m2 * c1 ) / (m1 - m2 )
108
+ return P
108
109
except :
109
110
return None
110
111
return P
@@ -166,7 +167,13 @@ def normalized_vector(self):
166
167
# angle = math.atan(self.slope)
167
168
angle = self .angle
168
169
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
170
177
171
178
##
172
179
## @var slope
@@ -239,10 +246,10 @@ def stan_inverse(self,y,x):
239
246
return atan2 (y ,x )+ 3.14159265
240
247
241
248
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 ))
246
253
247
254
def vicinity_points (point1 , point2 , thresh = 10 ):
248
255
return dist (point1 , point2 ) < thresh
@@ -289,4 +296,4 @@ def kub_has_ball(state, kub_id):
289
296
theta2 = math .atan2 (state .ballPos .y - state .homePos [kub_id ].y ,
290
297
state .ballPos .x - state .homePos [kub_id ].x )
291
298
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