You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于NSEW路径的无人机网格路线绘制与笛卡尔坐标输出异常

无人机网格坐标转换问题

我需要根据TXT文件中的NSEW方向指令,在网格中绘制无人机飞行路线,并输出无人机位置的笛卡尔坐标。当前运行代码时,要么网格显示正确但坐标输出错误,要么两者均出错。目前只能通过维护两个drone_pos变量临时解决问题,这显然冗余。我怀疑问题出在索引与坐标的转换逻辑上:

def file2list(file):
    """
    Helper function that converts a file to a list
    """
    with open(file) as f:
        lines = [word for line in f for word in line.split()]
    
    return lines 

def cart2index(x, y, height):
    idxX = x - 1
    idxY = height - y

    return [idxY, idxX]

def cart2indexreverse(x, y, height):
    idxX = x - 1
    idxY = height - y

    return [idxX, idxY]


def index2cart(x, y, height):
    Xcoord = x + 1
    Ycoord = height - y

    return [Xcoord, Ycoord]
...

    for row in grid:
        print(str(row))

*driver function*

当前输出坐标

[1, 10]
[2, 10]
[3, 10]
[3, 11]
[4, 11]
[5, 11]
[6, 11]
[6, 10]
[6, 9]
[6, 8]
[7, 8]
[8, 8]
[8, 9]
[8, 10]
[9, 10]
[9, 9]
[9, 8]
[9, 7]
[9, 6]
[8, 6]
[7, 6]
[6, 6]
[5, 6]
[5, 7]
[4, 7]
[3, 7]
[3, 6]
[3, 5]
[4, 5]
[4, 4]
[5, 4]
[5, 3]
[6, 3]
[7, 3]
[7, 4]
[8, 4]
[9, 4]
[10, 4]
[11, 4]
[12, 4]
[12, 3]
[11, 3]
[11, 2]
[11, 1]

正确坐标输出

[3, 12]
[3, 11]
[3, 10]
[2, 10]
[2, 9]
[2, 8]
[2, 7]
[3, 7]
[4, 7]
[5, 7]
[5, 6]
[5, 5]
[4, 5]
[3, 5]
[3, 4]
[4, 4]
[5, 4]
[6, 4]
[7, 4]
[7, 5]
[7, 6]
[7, 7]
[7, 8]
[6, 8]
[6, 9]
[6, 10]
[7, 10]
[8, 10]
[8, 9]
[9, 9]
[9, 8]
[10, 8]
[10, 7]
[10, 6]
[9, 6]
[9, 5]
[9, 4]
[9, 3]
[9, 2]
[9, 1]
[10, 1]
[10, 2]
[11, 2]
[12, 2]

内容的提问来源于stack exchange,提问作者JoeP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 20:20:17