Skip to content

Instantly share code, notes, and snippets.

@ntulip
Created June 20, 2011 13:06
Show Gist options
  • Save ntulip/1035573 to your computer and use it in GitHub Desktop.
Save ntulip/1035573 to your computer and use it in GitHub Desktop.
10:10 code
// 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