Created
June 14, 2010 21:06
-
-
Save ntulip/438294 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from http://blog.jgc.org/2010/06/1010-code.html | |
var alphabet = 'ABCDEFGHJKMNPQRVWXY0123456789'; | |
var base = alphabet.length; | |
function calculate_tt(lat, lon) { | |
lat += 90.0; | |
lon += 180.0; | |
lat *= 10000.0; | |
lon *= 10000.0; | |
lat = Math.floor(lat); | |
lon = Math.floor(lon); | |
var p = lat * 3600000.0 + lon; | |
var tt_num = p * base; | |
var c = 0; | |
for ( i = 1; i < 10; ++i ) { | |
c += ( p % base ) * i; | |
p = Math.floor( p / base ); | |
} | |
c %= 29; | |
tt_num += c; | |
tt_num = Math.floor(tt_num); | |
var tt = ""; | |
for ( i = 0; i < 10; ++i ) { | |
d = tt_num % base; | |
if ( ( i == 4 ) || ( i == 7 ) ) { | |
tt = " " + tt; | |
} | |
tt = alphabet.charAt(d) + tt; | |
tt_num = Math.floor( tt_num / base ); | |
} | |
return tt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment