Python全局变量定义故障排除

2024-06-25 07:20:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个将ECEF转换成Lat Lon的函数,我不明白Python为什么抱怨没有声明任何变量。例如,它最初抱怨变量aspesp没有声明,但我可以清楚地看到它们不是,而是高出两行。你知道吗

import math


def main():

    x = 504722.144
    y = -488562.32
    z = 4059321.82
    a = 6378137.0
    e = 8.1819190842622e-2
    asp = math.pow(a,2)
    esp = math.pow(e,2)

    b = math.sqrt(asq * (1-esp))
    bsq = math.pow(b,2)
    ep=math.sqrt((asq-bsq/bsq))
    p = math.sqrt(math.pow(x,2) + math.pow(y,2))
    th = math.atan2(a*z, b*p)
    lon = math.atan2(y,x)
    lat = math.atan2((z+math.pow(ep,2)*b*math.pow(math.sin(th),3)), (p- esq*a*Math.pow(Math.cos(th),3)))
    N = a/(math.sqrt(1-esq*math.pow(math.sin(lat),2)))
    alt = p / math.cos(lat) - N
    lon = lon % (2*math.pi)
    ret = [lat, lon, alt]
    print ret

    return ret
if __name__=='__main__':
    main()

Tags: 声明mainmathsqrtepasplonlat