2016-06-27 4 views
-2

ECEF를 Lat Lon으로 변환하는 함수가 있는데, 왜 Python이 변수가 선언되지 않는다고 불평하는지 이해할 수 없습니다. 예를 들어, 처음에는 변수 aspesp이 선언되지 않았지만 2 행 이상은 아닌 것으로 분명히 알 수 있습니다.Python 전역 변수 정의 문제 해결

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() 
+0

''asq '! ='asp'' ... – jonrsharpe

+0

정확하게'asq'를 정확히 정의 했습니까? – Selcuk

+0

당신은 [Ps and Qs를 기억하십시오] (https://en.wikipedia.org/wiki/Mind_your_Ps_and_Qs)를 배워야합니다 :) –

답변

1

"예를 들어, 그것은 처음에 변수가 esp는 선언되지 않은 ASP 불평 ... 그러나 나는 분명히 그들이 아니지만 두 줄 더 높은 것을 알 수있다."

당신은 거기에 오타가 있습니다. asp! = asq 따라서 'asq'는 알 수 없습니다.