def getTargetingCommand(self, time_diff): yDiff = self.targetY - self.tank.y xDiff = self.targetX - self.tank.x target_angle = atan2(yDiff, xDiff) relative_angle = normalize_angle(target_angle - self.tank.angle) shoot = False angleVel = relative_angle * 2#/time_diff return Command(self.tank.index, 0, angleVel, shoot)
def getTargetingCommand(self, time_diff): yDiff = self.targetY - self.tank.y xDiff = self.targetX - self.tank.x #print "cur angle: " + str(curAngle) +" tank at "+ str(self.tank.x)+ ", "+ str(self.tank.y) target_angle = atan2(yDiff, xDiff) relative_angle = normalize_angle(target_angle - self.tank.angle) #print "shots avail "+str(self.tank.shots_avail) #print str(self.tank.time_to_reload) + ", " + str(time_diff) shoot = False #abs(relative_angle) < abs(.0001) #shots_avail > 0 #time_to_reload angleVel = relative_angle * 2 #/time_diff return Command(self.tank.index, 0, angleVel, shoot)
def getTargetingCommand(self, time_diff): yDiff = self.targetY - self.tank.y xDiff = self.targetX - self.tank.x #print "cur angle: " + str(curAngle) +" tank at "+ str(self.tank.x)+ ", "+ str(self.tank.y) target_angle = atan2(yDiff, xDiff) relative_angle = normalize_angle(target_angle - self.tank.angle) #print "shots avail "+str(self.tank.shots_avail) #print str(self.tank.time_to_reload) + ", " + str(time_diff) shoot = False#abs(relative_angle) < abs(.0001) #shots_avail > 0 #time_to_reload angleVel = relative_angle * 2#/time_diff return Command(self.tank.index, 0, angleVel, shoot)
def transform( wheel1: Point, wheel2: Point, tail: Point, scene_center: Point, ): """ :return: ( robot_position, # position against scene center; angle, # angle against scene center; distance, # distance to scene center; ) """ robot_center = midpoint(wheel1, wheel2) # finds the tail point's prime and its projection line - the main one tail_prime = two_points_90(wheel1, robot_center) intersection_line = line(wheel1, wheel2) if not pts_same_side(tail, tail_prime, intersection_line): tail_prime = two_points_90(wheel2, robot_center) main_projection_line = line(tail, tail_prime) # finds center line's prime center_line = line(scene_center, robot_center) side_line = line(tail, wheel1) side_intersection = intersection(center_line, side_line) if side_intersection: side_line_prime = line(tail_prime, wheel1) else: side_line = line(tail, wheel2) side_intersection = intersection(center_line, side_line) side_line_prime = line(tail_prime, wheel2) # noinspection PyTypeChecker side_intersection_projection_line = parallel_line(main_projection_line, side_intersection) side_intersection_prime = intersection(side_line_prime, side_intersection_projection_line) center_line_prime = line(robot_center, side_intersection_prime) # computes position, angle and distance center_line_projection = parallel_line(main_projection_line, scene_center) center_prime = intersection(center_line_projection, center_line_prime) dist = distance(center_prime, robot_center) / distance(robot_center, tail_prime) robot_position = robot_center - center_prime angle = math.degrees(normalize_angle( three_pts_angle(tail_prime, robot_center, center_prime) - math.pi)) return Object(robot_position, angle, (dist * ROBOT_UNIT))
def set_heading(self, heading): """Sets the orientation of the game object.""" self.dirty_image = self.dirty_image or self.heading != heading self.heading = geometry.normalize_angle(heading)
def test_normalize_angle_neg_greater_360(self): angle = -495 self.assertEqual(geometry.normalize_angle(angle), 225)
def test_normalize_angle_greater_360(self): angle = 890 self.assertEqual(geometry.normalize_angle(angle), 170)
def test_normalize_angle_neg(self): angle = -60 self.assertEqual(geometry.normalize_angle(angle), 300)