Re: Worldmap mercator projection - Latitude to Y calculation.

Paul <[email protected]> Fri, 16 Jan 2026 05:08:22 -0500
Newsgroups alt.comp.os.windows-xp,alt.windows7.general,alt.comp.os.windows-10
Organization A noiseless patient Spider
Message-ID <[email protected]>
On Thu, 1/15/2026 12:25 PM, J. P. Gilliver wrote:
> On 2026/1/14 8:24:17, R.Wieser wrote:
>> Hello all,
>>
>> I have a world map using the Mercator projection, and would like to plot 
>> some stuff on it using Latitude and Longitude.
>>
>> The problem is that I can't seem to get the formule I found to spit out the
>> correct value for Y.
>>
>> -- The map :
>>
>> https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Mercator_projection_Square.JPG/250px-Mercator_projection_Square.JPG
>>
>> -- The formula :
>>
>> Y = ln( tan(latitude) + sec(latitude) )
>>
>> where "ln(...)" is log(...) / log(10)
>>
>> ... at least, that is what I could google about it.
> 
> Rather than Googling the formula, my first thought was to go back to
> first principles: as the name implies, a map projection can be thought
> of as being created by shining a light through the earth (globe) onto a
> sheet of paper - either flat and fixed to the globe at one point, or -
> more commonly - a cylinder wrapped round the globe, touching at one
> circle (often the equator), and then unrolled. Once this is realised,
> basic geometry should make calculation of the co-ordinates fairly simple.
> 
> Unfortunately, to do this, one needs to know where the nominal light
> source is. And - despite it being a _long_ article - I can't find a
> statement of this in the Wikipedia article about the Mercator projection
> - other that that - I _think_ - it _isn't_ the centre of the earth
> (so-called "radial"), though is often thought to be (certainly Google's
> AI thinks it is).
> 
> If anyone _can_ find out where the light source point is for the
> Mercator projection, I'd love to know! (And it would answer Rudy's
> question.)
> 
> (One other position for the light source I remember from last time I
> looked into this - which was probably over 40 years ago! - is on the
> opposite surface of the globe to the projection point (i. e. sort of
> tracking round opposite the map "printing"); I don't think it's that,
> though, as that would show the poles, though still distorted.
> 
> If it _is_ light-source-at-centre, then the Y co-ordinate would just be
> the tangent of the latitude (scaled appropriately for the map size).
> Even if it isn't, this _may_ be close enough - try a few places.
> 

https://en.wikipedia.org/wiki/Mercator_projection

     [Picture] Use Download Original for best result (CoPilot output)

      https://i.postimg.cc/SQLZbfvY/mercator-equation.gif

The NASA Panoply program (written in Java and requiring a Java11 JRE),
offers a menu with at least 100 different projections, and Mercator
has two (not that it matters).

I don't think there is anything mysterious about this.

And actually harnessing Panoply to do something useful,
that's almost impossible. An alternative is something called
GGPlot.

I did a PostScript print of the NASA overlap map.

No matter what you set the paper to, the coordinates of the unit
square were only 406x406 pixels (which means the picture itself sucks).

   406x406 square subtract 1482 on X, 989.5 on Y

But the beauty of the PostScript, is you find this inside.
This would be drawing a piece of coastline with line segments.
PostScript supports transform matricies, so they can do anything
they want with the item once selecting a coordinate system.

1553.23376 1231.24414 moveto
1553.21582 1231.28955 lineto
1553.17749 1231.35498 lineto
1553.15955 1231.4231 lineto
1553.12134 1231.44446 lineto
1553.14038 1231.46716 lineto

I scaled that, extracted the points, didn't plot lines, just dots,
and made a pbm file (netpbm black and white). The purpose of not plotting
lines, was to get less visual clutter. My picture sucks when viewing
the whole thing (it isn't dark enough). But when you zoom into pieces
of the picture, it looks dark enough then to use.

Your coordinates for NYC, where did you get those coords ???
There is an article in Wikipedia I used, complete with a tiny
map widget when you click an icon near the coord info.

40 42 46     -74 0 22       New York City value (Wikipedia)

40.71277778  -74.00611111   DMS to D via https://www.latlong.net/degrees-minutes-seconds-to-decimal-degrees

X=0.294427  Y=0.375981      merc.exe (the CoPilot program)

That means, on my 10000x10000 pixel map, I plot a dot at (2944,3760).

Now, some weirdness to throw in. GIMP measures from lower left corner.
I think the equation measures from upper left corner. Yet, when I
plotted my PBM, it was upside-down as viewed on the screen, and I
had to do a Flip-Vertical so the map read correctly. So when GIMP reads
(2944,3760) off the mouse cursor as I move around, that's kinda measuring
from the upper left corner. Otherwise, I would have needed to do 10000-3760
or so. Which turned out not to be necessary.

The PBM file looks nicer when zoomed in, and that's what you're looking
at here, is just a portion of my Mercator.

    [Picture]  Use Download Original when buried in adverts

     https://i.postimg.cc/P5vhvS3w/NYC-coord3.gif

There is still some error there. Even if I made an allowance for
a one pixel error in plotting the picture, I don't think that covers
it and I might be off two or three pixels left-right.

I think the equation is pretty close. But I'm not happy that
there is an error still there.

    Paul