【问题标题】:Cloud Flight Coding Contest - Mars Rover云飞行编程大赛 - 火星探测器
【发布时间】: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


【解决方案1】:

我也被卡住了,但到目前为止我对前 2 个输入有效:

import math

WheelBase, Distance, SteeringAngle = 1, 1, 30.00
WheelBase, Distance, SteeringAngle = 2.13, 4.30, 23.00

WheelBase = float(WheelBase)
Distance = float(Distance)
SteeringAngle = float(SteeringAngle)

TurnRadius = abs(WheelBase / math.sin(math.pi * (SteeringAngle) / 180))

NewDirection = 180 * (Distance / TurnRadius) / math.pi

chord = 2 * TurnRadius * math.sin(math.pi * NewDirection / 360)

y = TurnRadius * math.sin(math.pi * (NewDirection) / 180)

x = math.sqrt(chord ** 2 - y ** 2)

print(round(x, 2), round(y, 2), round(NewDirection, 2))

print(chord)
print(math.sqrt(x ** 2 + y ** 2))

【讨论】:

    猜你喜欢
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 2017-02-15
    • 1970-01-01
    • 2017-06-02
    • 2016-09-13
    • 2016-05-26
    • 2017-12-03
    相关资源
    最近更新 更多