2016-06-27 3 views
-2

Ich habe eine Funktion, die ECEF in Lat Lon konvertiert, und ich verstehe nicht, warum Python beschwert, dass keine der Variablen deklariert sind. Zum Beispiel beschwert es sich zunächst, dass die Variablen asp und esp nicht deklariert sind, aber ich kann deutlich sehen, dass sie nur zwei Zeilen höher sind.Python Globale Variable Definition Trouble Shooting

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

Wo haben Sie' asq' genau definiert? – Selcuk

+0

Sie müssen lernen, [Ihre Ps und Qs zu beachten] (https://en.wikipedia.org/wiki/Mind_your_Ps_and_Qs) :) –

Antwort

1

„Zum Beispiel, es beschwert sich zunächst, dass Variablen ASP ist eine esp nicht deklariert werden ... aber ich kann deutlich sehen, dass sie nicht nur zwei Zeilen höher.“

Sie dort einen Tippfehler haben. asp! = asq, daher ist 'asq' unbekannt.