【发布时间】:2022-07-29 02:54:18
【问题描述】:
正在处理 Mars Rover 编码问题并且卡在第 2 级。尝试调试但我看不到它,并且在当前级别完成之前不会让我继续前进。
问题描述如下:
以一定的转向角行驶一定距离后,计算流动站的位置和方向。
输入:轴距、距离、转向角(2 个小数浮点数) 输出:X、Y、新方向角度
示例: 在: 1.00 1.00 30.00 输出:0.24 0.96 28.65
有人知道一些演练、解决方案等或更多示例的链接吗?
底部有编码问题的图片链接
谢谢
https://catcoder.codingcontest.org/training/1212/play
## Level 1 - calculate the turn radius ##
## level1 2 - calculate new position and angle
import math
## solution works for this data
WHEELBASE = 1.00
DISTANCE = 1.00
STEERINGANGLE = 30.00
#WHEELBASE = 1.75
#DISTANCE = 3.14
#STEERINGANGLE = -23.00
def calculateTurnRadius(wheelbase, steeringangle):
return round(wheelbase / math.sin(math.radians(steeringangle)), 2)
def calculateNewDirection(wheelbase, steeringangle, distance):
turnRadius = calculateTurnRadius(wheelbase, steeringangle)
theta = distance / turnRadius
#brings theta to within a 180 arc
while theta >= math.pi * 2:
theta -= math.pi * 2
while theta < 0:
theta += math.pi * 2
# calculate theta with basic sin and cos trig
x = turnRadius - (math.cos(theta) * turnRadius)
y = math.sin(theta) * turnRadius
x = abs(round(x, 2))
y = round(y, 2)
theta = math.degrees(theta)
theta = round(theta, 2)
return x, y, theta
print(f"Turn Radius = {calculateTurnRadius(WHEELBASE, STEERINGANGLE)}")
print(f"{calculateNewDirection(WHEELBASE, STEERINGANGLE, DISTANCE)}")
Turn Radius = 2.0
(0.24, 0.96, 28.65)
[1]: https://i.stack.imgur.com/tDY2u.jpg
【问题讨论】:
-
请说明您遇到的问题到底是什么。指向问题的链接将来可能会中断,因此总结您需要做什么以及您的问题是什么,会有所帮助。如果您遇到错误,请包括回溯错误。
-
转弯半径是
wheelbase / tan(steering_angle),而不是sin。为什么要四舍五入? -
感谢您的回复:0 我只是按照问题中给我的公式,并被要求四舍五入到 2 位数。
标签: python trigonometry