Experimental projections

General discussion of map projections.
daan
Site Admin
Posts: 977
Joined: Sat Mar 28, 2009 11:17 pm

Re: Experimental projections

Post by daan »

:lol:
Milo
Posts: 271
Joined: Fri Jan 22, 2021 11:11 am

Re: Experimental projections

Post by Milo »

A while back I wrote a program for making pixel-perfect renderings of arbitrary pseudocylindrical equal-area projections. How arbitrary? Well, I stress-tested it with this:
koch.png
koch.png (93.01 KiB) Viewed 2526 times
Or if you prefer a two-hemisphere version so Africa isn't so squashed (since that's obviously the only problem with this projection):
koch-2hemi.png
koch-2hemi.png (167.21 KiB) Viewed 2526 times
Milo
Posts: 271
Joined: Fri Jan 22, 2021 11:11 am

Re: Experimental projections

Post by Milo »

Here's another pseudocylindrical projection. Unlike above, I didn't bother with pixel-perfect interpolation for this one.
devils_projection.png
devils_projection.png (461.71 KiB) Viewed 2509 times
This is a conformal projection. Honest.

Okay, so it has some singularities. Okay, a lot of singularities. Uncountably-infinitely many singularities, and they're topologically dense too. But the singularities still form a set of Lebesgue measure zero, which means that the projection is conformal "almost everywhere" in the measure-theoretic sense.

I got the idea after observing that it is impossible for any pseudocylindrical projection to be conformal unless it is simply cylindrical (and therefore the Mercator projection). But I'm a stubborn kind of person, so being told I can't do something just makes me want to figure out how to do it.


Highlight that suspicious gap between these lines for some spoilers.
brsr
Posts: 11
Joined: Sat May 22, 2021 5:25 pm

Re: Experimental projections

Post by brsr »

Milo wrote: Sun Nov 21, 2021 11:41 am This is a conformal projection. Honest.
The boundary looks like the Cantor function: is that a coincidence?
PeteD
Posts: 251
Joined: Mon Mar 08, 2021 9:59 am

Re: Experimental projections

Post by PeteD »

brsr wrote: Sun Nov 21, 2021 12:10 pm The boundary looks like the Cantor function: is that a coincidence?
With a name like the "devil's projection", it can't be a coincidence.
daan
Site Admin
Posts: 977
Joined: Sat Mar 28, 2009 11:17 pm

Re: Experimental projections

Post by daan »

Interesting stress tests!

What is “pixel-perfect”?

— daan
Milo
Posts: 271
Joined: Fri Jan 22, 2021 11:11 am

Re: Experimental projections

Post by Milo »

brsr wrote: Sun Nov 21, 2021 12:10 pmThe boundary looks like the Cantor function: is that a coincidence?
PeteD wrote: Sun Nov 21, 2021 12:43 pmWith a name like the "devil's projection", it can't be a coincidence.
Close, but not quite. It's actually the Minkowski question mark function, also known as the "slippery devil's staircase", which has similar properties to the Cantor function, but looks smoother (although it is, of course, not "smooth" in the normal calculus sense of being continuously-differentiable).
daan wrote: Sun Nov 21, 2021 1:14 pmInteresting stress tests!

What is “pixel-perfect”?
For the most part, just boring ol' interpolation (if the area covered by a pixel of the projection includes multiple pixels of the raw input data, then they're properly weighted and averaged), but it does go a little deeper than that.

My original goal in writing that program was to explore the Tobler hyperelliptical projection better than available tools let me do. NASA's G.Projector, which I usually use, does include the Tobler projection, but does not allow variation of the exponent (presumably, it's hardcoded to use the 2.5 value that Wikipedia lists as Tobler's favorite), which I wanted to experiment with.

This proved to be frustrating, because there's no easy way to compute the area of a hyperellipse, let alone a hyperellipse segment below a certain y value. Other implementations I was able to find relied on numerical integration, but that's always annoying to work with because you need to decide on a step size: too coarse, and your results are inaccurate, but too fine, and you're just wasting processor time. Also, you need the partial integral for every scanline, and so if you compute those the naive way by rerunning the numerical integration algorithm for each value, you'll be wasting a lot of time repeating the same calculations.

This was resolved when I had the epiphany that I know exactly what accuracy I need to integrate to: one pixel. Or more accurately, 1/255th of a pixel, since that's the color depth of modern computer monitors.

So what I did was write a program that doesn't actually know or care at all what the formulation of Tobler's projection is. It just inputs a "mask file" that depicts a pixel-accurate hyperellipse (white for pixels inside the hyperellipse, black for pixels outside it, grayscale antialiasing for pixels on the edge where the grayscale value matches the percentage of the pixel that should be covered), counts the pixels, and uses that to make a projection.

Of course, once I had that, it wasn't actually limited to just Tobler's projection. I could compute literally any pseudocylindrical equal-area projection, so long as I could obtain a mask file that depicts the shape of the desired projection. (The data of the mask file is, in fact, preserved verbatim as the alpha channel of the output image.) Writing a program to draw the interior of a Koch snowflake was, all things considered, pretty easy.

...And then the devil's projection uses exactly the same kind of messy numerical integration that I previously avoided. Well, not quite exactly: Tobler's hyperelliptical projection defines x/longitude scale relative to the y coordinate, whereas the devil's projection defines x/longitude scale relative to the latitude coordinate. Either way, this defined scale then needs to be integrated in order to figure out the relationship between the y and latitude coordinates, but the difference means that I couldn't use the same technique for the devil's projection that I did for the equal-area projections, even if I wanted to.

To be precise, the devil's projection's x scale is defined as the cosine of the Minkowski question mark function of latitude. Well, adjusted for pi: cos(minkowski(latitude/pi)*pi). That and the knowledge that it's conformal should be enough to reconstruct it. (Contrast the sinusoidal projection, whose x scale is simply the cosine of latitude. The Minkowski function distorting the cosine means the devil's projection isn't equal-area anymore, which is to be expected since the point is to be conformal, but it at least comes closer than it would have if I hadn't included the cosine part. Also, the Minkowski question mark function has special behavior on the rational numbers, so this reflects the importance of angles which are rational multiples of pi - that's part of why I put the cosine on the outside and the Minkowski function on the inside of the formula.)
daan
Site Admin
Posts: 977
Joined: Sat Mar 28, 2009 11:17 pm

Re: Experimental projections

Post by daan »

I’m confused by the statement that it’s “conformal”. It doesn’t look conformal, although it’s hard to say, given the stepping and the effects stepping would have. More to the point, how does “conformal” have meaning in such a function? (Or in a continuous mapping of such a function.) I suppose it meets the Cauchy-Riemann equalities (by virtue of their partials being 0 almost everywhere), but the Cauchy-Riemann equalities presuppose absolute continuity, which this function does not have.

— daan

Update: Or, well, I suppose that cos takes care of that. Hm.
¯\_(ツ)_/¯
Milo
Posts: 271
Joined: Fri Jan 22, 2021 11:11 am

Re: Experimental projections

Post by Milo »

daan wrote: Sun Nov 21, 2021 2:35 pmI’m confused by the statement that it’s “conformal”. It doesn’t look conformal, although it’s hard to say, given the stepping and the effects stepping would have. More to the point, how does “conformal” have meaning in such a function? (Or in a continuous mapping of such a function.) I suppose it meets the Cauchy-Riemann equalities (by virtue of their partials being 0 almost everywhere), but the Cauchy-Riemann equalities presuppose absolute continuity, which this function does not have.
Well, sure, it's drastically abusing the definition of "conformal".

I used the rule that states that a projection is conformal if it satisfies the following two formulae:
(dx/dlatitude)^2 + (dy/dlatitude)^2 = ((dx/dlongitude)^2 + (dy/dlongitude)^2) / cos(latitude)^2
(dx/dlatitude + dy/dlongitude/cos(latitude))^2 + (dy/dlatitude - dx/dlongitude/cos(latitude))^2 = 0
I wasn't familiar with the Cauchy-Riemann equations, those do look a lot simpler :). Should maybe take a closer look at them. Wikipedia's article on them doesn't mention a requirement of absolute continuity...

By the properties of the Minkowski function (and all other "devil's staircases"), dx/dlatitude is zero almost everywhere. (The cosine doesn't disrupt this thanks to the chain rule.) By the properties of being a pseudocylindrical projection, dy/dlongitude is zero absolutely everywhere. Thus both equations above simplify to:
dy/dlatitude = dx/dlongitude / cos(latitude)
With dx/dlongitude known per definition (and being a function only of latitude), the relationship between y and latitude can then be determined through numerical integration.

The devil's projection doesn't look shape-preserving because, for any shape that has actual area, it'll include some of the latitudes where the projection has singularities. In the same way that even though Minkowski's question mark has derivative zero almost everywhere, it only looks particularly horizontal at the rational numbers (the smaller the denominator, the larger the apparent flat section). However, while the less-flat-looking sections are that way because they have "denser" singularities in some sense, those singularities still form a null set. Zoom in on a non-flat-looking section enough, and you should eventually see how it's actually composed of flatter treads with large risers between them.

Take a look at the projection's graticule:
devils_graticule.png
devils_graticule.png (9.15 KiB) Viewed 2488 times
(Purple lines are multiples of 30 degrees, green lines are odd multiples of 15 degrees.) You'll notice that these do look pretty perpendicular to each other, like a cylindrical projection would be and unlike most pseudocylindrical projections. That's not quite enough to establish conformality, but it's pretty evocative. For the less "neat" latitude values, or for lines other than meridians or parallels, this won't be as obvious, but for any two lines, you should still find that the angle between them starts looking about right if you zoom in enough.

To be a little more formal: so long as a projection is differentiable at a point (the derivative doesn't need to be absolutely continuous or anything, it just needs to exist), the projection of a differentiable curve passing through that point will also be a differentiable curve, and can thus be given a tangent line. The angle between two curves can then be defined as the angle between their tangent lines. These angles are preserved.
daan wrote: Sun Nov 21, 2021 2:35 pmUpdate: Or, well, I suppose that cos takes care of that. Hm.
How does that help? I could have done the same thing without it, I just don't think it would have looked as good.
PeteD
Posts: 251
Joined: Mon Mar 08, 2021 9:59 am

Re: Experimental projections

Post by PeteD »

Just to make sure that I understand what you're doing here, is it essentially this:
pyramidal Mercator.png
pyramidal Mercator.png (128.17 KiB) Viewed 2476 times
?

That's a Mercator projection cut into strips. Each strip has been rescaled to have a standard parallel along which scale is correct. Here, the standard parallels have been chosen to coincide with the Tissot ellipses, so not only is every Tissot ellipse a circle, they're also all the same size. Of course, this doesn't make the projection equal-area, but as the number of strips tends to infinity, the projection does become the equal-area sinusoidal projection.

As far as I understand, this is essentially what you're doing, except you're cutting the Mercator along the points where Minkowski's question mark function isn't absolutely continuous, and the strips are rescaled such that their lengths correspond to the cosine of Minkowski's question mark function. As a result, you get a projection that, unlike the one above, is continuous everywhere (but not absolutely continuous everywhere). Is that right? If not, what are you doing differently?

Incidentally, it occurs to me that the strips of the above projection could be put onto sliders, like the beads of an abacus, so that you could make whichever part of the map you're looking at line up, though you'd probably need to cut it into a greater number of smaller strips to make the jumps in scale less severe.
Post Reply