Palagpat Coding

Fun with JavaScript, game theory, and the occasional outbreak of seriousness

Tuesday, May 19, 2009

Mapping headaches

Note: the next entry in my Cloning Zelda series is still in progress; for now, enjoy the following post on something completely different.

I've been experimenting with Google's KML standard for the past few days, as a sort of a gateway into understanding how map projections work. Remember all that trigonometry you learned back in middle/high school, and you always wondered when you would ever use it (aeronautical engineers excepted, of course: you guys probably do this stuff all the time)? Well, anyway, I ran smack into that wall head-first. The most interesting thing I've learned is WHY the Mercator projection gets so weird and distorted toward the north and south poles (warning, it's rather math-y).

Basically, Mercator's big idea was to shove the Earth into a giant imaginary cylinder, and unfold it onto the inside of this giant invisible tube, then unwrap and flatten the tube. Simple so far, right? Except for two problems: first, if you've ever peeled an orange, you know that the curved surface of a sphere (or nearly-a-sphere) doesn't lay flat unless you split it into fairly narrow strips. This is why some maps get broken into chunks: the Interrupted Sinusoidal and Waterman "Butterfly" are two of the more interesting of these, but there are a lot of others.

The second problem with rectangular map projections involves the poles, and this one was the big revelation to me: the trigonometric formula that Mercator used in his eponymous projection only works until you get close to the poles, at which point the horizontal stretching approaches infinity. No wonder, then, that Greenland looks as big as South America, and Alaska almost as big as Brazil!

Back to KML: in trying to get a handle on Mercator's latitude-to-y-coordinate formula, I realized that I couldn't define the top and bottom points of my map, because they were infinite! So, how on earth was I supposed to calculate the distances in between, if I didn't have a baseline? I whipped up a simple test KML file to plot the main latitude lines in 10-degree steps from -80° to 80° (these are white), and the main circles of latitude (Equator, Artic/Antarctic Circle, Tropics of Cancer/Capricorn) in red. My first test file also included white lines for several latitudes approaching the poles so I could get an idea of what they looked like in Google Maps... surprise! Because of the problem with infinity, Google Maps doesn't actually SHOW you the whole Earth... any lines I tried to draw further north or south than 85 degrees actually broke the map code! If you try to click on the links for N 88°, N 89°, or their south equivalents, you'll be shown a line that plots completely off the map! After some trial and error, I've determined that Google's map appears to extend from 85° north to 85° south, omitting much of the Arctic Sea and Antarctica in the process! Admittedly, this is probably no big deal to 99.99999% of the people using Google's amateur cartography tools, but it's interesting to see how Google's much-vaunted engineers tackle an intractable, literally infinite problem space.

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home