python坐标旋转_Python - 用于旋转/移动指令的坐标

您可以沿着北/南或东/西轴移动,因为您的旋转限制在90度。

您可以观察到任何运动都有一个北/南组件和一个东/西组件。

如果你的动作一致,那么你离下一步只有90度转弯:

1. turn east or west

2. move east or west

3. turn north or south

4. move north or south

5. You should be at your target

6. turn east or west

7. move east or west

8. turn north or south

9. move north or south

10. you should be at your (next) target...等

如果我们假设您的机器人朝北开始,那么您的环路应先转向东/西,然后移动,然后转向北/南。

这是一个开始。这可能是您的全局数据和主要代码。

Robot_pos = coordinates[0]

Robot_facing = NORTH

for next_pos in coordinates[1:]:

move_robot(next_pos)如果我们假设x是东/西,y是北/南,那么你对move_robot有类似的东西:

def move_robot(new_pos):

"""

Move robot from ``Robot_pos`` to ``new_pos`` given. The robot

is assumed to be facing either north or south upon entry, so

east/west movement is done first.

"""

delta_x = ...

turn_robot(EAST or WEST)

forward( some amount )

# similarly for Y你必须在turn_robot()代码中有点聪明才能优化转向,无论你是开始面向正方向还是负方向。但它应始终是一个90度的旋转。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值