云飞行编码比赛 - 火星漫游者

发布于 2025-01-22 16:30:49 字数 1651 浏览 2 评论 0原文

做火星漫游者编码问题,并且陷入了2级。试图调试,但我看不到它,它不会让我进步直到当前级别完成。

问题描述如下:

以一定的转向角度驾驶一定距离后,计算漫游者的位置和方向。

输入:轴距,距离,方向盘(2个小数小数) 输出:X,Y,新界面角

示例: 在:1.00 1.00 30.00 出局:0.24 0.96 28.65

有人知道某些步行,解决方案等的任何链接还是更多示例?

底部有一个指向编码问题的图像链接,

请感谢

https:/ /训练/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.sstatic.net/tDY2u.jpg

Doing the Mars Rover coding problem and am stuck at level 2. Trying to debug but I just can't see it and it wont let me progress until current level is finished.

Problem Description as follows:

Calculate the position and the direction of the rover after driving a certain distance with a certain steering angle.

Input: WheelBase, Distance, SteeringAngle (2 decimal floats)
Output: X, Y, NewDirection Angle

Example:
In: 1.00 1.00 30.00
Out: 0.24 0.96 28.65

Anybody know of any links to some walk throughs, solutions etc or more examples?

There is an image link to the coding problem at the bottom

Thanks

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.sstatic.net/tDY2u.jpg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赤濁 2025-01-29 16:30:49

我并没有真正看过您的代码,但是我从1级到4的解决方案都得到了解决方案。因此,这是我的2级代码。

import math

def turn_radius(wheel_base, steering_angle):
    radius: float = wheel_base/math.sin(math.radians(steering_angle))
    print (f"{radius:.2f}")

    return radius

def get_position(distance, steering_angle, radius):
    angle = (distance*180)/(math.pi*radius)
    y = (math.sin(math.radians(angle)) * radius)
    x = radius - (math.cos(math.radians(angle)) * radius)

    while angle < 0:
        angle = 360 + angle
    
    if angle == 360:
        angle = 0

    print(f"{x:.2f} {y:.2f} {angle:.2f}")

if __name__ == "__main__":
    wheel_base = 2.7
    distance = 45
    steering_angle = -34

    if steering_angle == 0:
        steering_angle = 360

    radius = turn_radius(wheel_base ,steering_angle)
    get_position(distance, steering_angle, radius)

I haven't really looked at your code, but I got the solutions from level 1 to 4. So here's my code for level 2.

import math

def turn_radius(wheel_base, steering_angle):
    radius: float = wheel_base/math.sin(math.radians(steering_angle))
    print (f"{radius:.2f}")

    return radius

def get_position(distance, steering_angle, radius):
    angle = (distance*180)/(math.pi*radius)
    y = (math.sin(math.radians(angle)) * radius)
    x = radius - (math.cos(math.radians(angle)) * radius)

    while angle < 0:
        angle = 360 + angle
    
    if angle == 360:
        angle = 0

    print(f"{x:.2f} {y:.2f} {angle:.2f}")

if __name__ == "__main__":
    wheel_base = 2.7
    distance = 45
    steering_angle = -34

    if steering_angle == 0:
        steering_angle = 360

    radius = turn_radius(wheel_base ,steering_angle)
    get_position(distance, steering_angle, radius)
寒江雪… 2025-01-29 16:30:49

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

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))

I'm also stuck, but what I have so far works for the first 2 inputs:

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))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文