def _drive_to_1(
self,
speed: int,
pos_x: float,
pos_y: float
) -> None:
diff_x = pos_x - self._pos_x
diff_y = pos_y - self._pos_y
if abs(diff_x) > abs(diff_y):
direct = math.degrees(math.atan(diff_y/diff_x))
else:
fract = diff_x / diff_y
sign = math.copysign(1, fract)
direct = sign * 90 - math.degrees(math.atan(fract))
if diff_x < 0:
direct += 180
self._rotate_to(speed, direct)
评论列表
文章目录