Miller Projection

I was talking to my colleague the other day about a problem he was having with a new Location Editor that he was making for the university. The goal of the program was to take Latitude/Longitude coordinates and transpose them to (x,y) coordinates on a image of a map. I do want to put a disclaimer that my colleague basically did all the work to solve this problem. I am merely describing the math of his solution.

In stating the obvious, the planet we live on is basically a sphere. However, because we only live on the surface, we still only have two dimensions to map. However, in order to represent the surface of the earth, we will need some kind of projection which will change (Latitude,Longitude) coordinates to (x,y) coordinates. I am going to be using a World Map which uses a Miller Projection. However, you can easily use a different projection like a Mercator projection or a Gall-Peters projection.

A Miller projection is obtained by projecting all points on the surface of the earth onto a cylinder.

Once you projected the earth onto a cylinder, you can then unroll the cylinder surface onto a plane. If you do this, you will get the following world map.

It can be shown that the x,y coordinates can be obtained by the following relationship. Please note that the longitude and latitude are in radians not degrees.

 x = longitude
 y = 1.25 \cdot ln(tan(\pi / 4 + .4 \cdot latitude))

However, in order to project these x,y coordinates onto an image, we are going to need to change these formulas a bit. First off, the miller coordinates (which I will represent as x’,y’ from now on), assumes the following coordinate system.

The big things to note about the coordinate system is that
1) y=0 runs across the equator.
2) x=0 runs across the prime meridian.
3) The range of possible values are roughly x = 0 .. 6.28 and y =-2.30 .. 2.30.

However, we don’t care about the Miller Coordinate system. We want to use the coordinate system of the image. First off, the image coordinate system uses pixels as a unit length instead of a miller unit. Secondly, the y axis in the image coordinate system is in the opposite direction as the miller y’ axis. This is because (x,y)=(0px,0px) should be the top-left corner of the image which is the standard coordinate system that computers use for images. And lastly, the image doesn’t have to be the entire world map. The image could be an image of North America instead of the World.

This means we will have to apply the following projections (Long, Lat) \rightarrow (x^\prime,y^\prime) \rightarrow (x,y).

First, before I describe the transformation, I want to define the following constants:
 LeftLong = Longitude ~ of ~ Left ~ Side ~ of ~ the ~ Image
 RightLong = Longitude ~ of ~ Right ~ Side ~ of ~ the ~ Image
 TopLat= Latitude ~ of ~ Top ~ of ~ the ~ Image
 BottomLat= Latitude ~ of ~ Bottom ~ of ~ the ~ Image
 ImageWidth = Width ~ of ~ Image ~ in ~ Pixels.
 ImageHeight = Height ~ of ~ Image ~ in ~ Pixels.

As I mentioned above, the Miller projections are defined as:
 x^\prime = M_x(long) = long
 y^\prime = M_y(lat) = 1.25 \cdot ln(tan(\pi / 4 + .4 \cdot lat))

All we need to do is to apply the following transformation to get from (long, lat) to (x, y).

 x = (M_x(long)- M_x(LeftLong)) \cdot (\frac{ImageWidth}{M_x(RightLong)- M_x(LeftLong)})
 y = (M_y(TopLat)- M_y(lat)) \cdot (\frac{ImageHeight}{M_y(TopLat)- M_y(BottomLat)})

The nice thing about this formula is that it is really easy to move to a map with a different projection. All you need to do is to apply a different projection function for M_x(long) and M_y(lat). For example, the Mercator projection would have the functions:

 x^\prime = G_x(long) = long
 y^\prime = G_y(lat) = ln( tan(lat) + sec(lat))