Re: Worldmap mercator projection - Latitude to Y calculation. - last try

Paul <[email protected]> Mon, 19 Jan 2026 19:21:00 -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 Mon, 1/19/2026 3:11 PM, R.Wieser wrote:
> As I cannot get any formule to work I'm going to try this one last time.
> 
> Below are two formules for converting a lattitude on a Mercator-projection 
> map into a -1 ... +1 result that needs to be multiplied by half the 
> maps-images height and subtracted from the equator (the map-images top-left 
> is 0,0).
> 
> I've split the calculations up into multiple parts, hoping that someone can 
> tell me where one, or perhaps both, go awry.
> 
> -- Formule: ln( tan(latitude) + sec(latitude) )
> 
> Lat: 39
> DegToRad(39) -> 0.680952
> tan(0.680952) -> 0.810238
> sec(0.680952) -> 1/cos(0.680952) -> 1.287045
> ln(0.810238+1.287045) -> log(0.810238+1.287045)/log(10) -> 0.321657

  ln(2.097283) = 0.740643   # Via the ln() button on my calculator
                            # Calc is a cheap Canon F502
                            # http://www.datamath.org/Related/Canon/Images/F-502.jpg
> 
> 0.321657 is *way* too high.

https://luckytoilet.wordpress.com/2010/11/07/notes-on-mercators-projection/

         x = lambda                          # longitude in radians ?
                                             # Means our plot is not a unit square, as given

         y = ln( sec(theta) + tan(theta) )   # I cannot copy the equation as it is mathml
                                             # and will only confuse matters. 1/3rd down the page,

The plot origin must not be where we think it is. Notice how in a lot
of these mathematics discussions, nobody labels a damn thing. The
range on y is 0 to some positive number. X must be in the center of
the plot, so plus and minus lambdas move to either side for us.

> 
> -- Formule: log( tan(PI/4.0 + rad/2.0) ) / (2.0 * PI)
> 
> Lat: 39
> DegToRad(39) -> 0.680952
> tan(PI/4+0.680952/2) -> 2.098991
> log(2.098991) -> 0.741457
> 0.741457/(2*PI) -> 0.117959
> 
> 0.117959 is *way* to low

But it is 0.5 minus that number, so 0.382 .

        double rad = lat * PI / 180.0;
        double y = 0.5 - (log(tan(PI/4.0 + rad/2.0)) / (2.0 * PI));

And again, we have to evaluate the range of the equation and see how
we can fit it to the plot and make sense of it. In a previous post,
I ran merc.exe and entered some numbers to generate a range. So we
can see which direction it is moving. The Y axis seems to be down
the page on this one. I put this text into a previous post and I removed
all the distracting latitude text when making this table.

Enter Latitude in degrees: -80    Y=0.887741
Enter Latitude in degrees: -50    Y=0.660855
Enter Latitude in degrees: -30    Y=0.587425
Enter Latitude in degrees:   0    Y=0.500000
Enter Latitude in degrees:  30    Y=0.412575 \___ 39 degrees is between these two
Enter Latitude in degrees:  50    Y=0.339145 /
Enter Latitude in degrees:  80    Y=0.112259

   Paul