• Worldmap mercator projection - Latitude to Y calculation.

    From R.Wieser@3:633/10 to All on Wed Jan 14 09:24:17 2026
    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.

    where "sec(...)" is 1/cos(...)

    -- The test data :

    New York : Latitude = 39 (Longitude = -77)

    -- Applying the formula and checking the partial results :

    RadLat = DegToRad(39) -> 0.680952380952381

    Temp = tan(RadLat) + 1/cos(RadLat) -> 2.09728292053088

    log(Temp)/log(10) -> 0.321657020135087

    Multiplying half the maps height by the above tells me that New York is
    located somewhere in Canada. :-(

    Can anyone tell me what goes wrong here ?

    Regards,
    Rudy Wieser




    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Ammammata@3:633/10 to All on Wed Jan 14 12:13:13 2026
    After serious thinking R.Wieser wrote :
    Can anyone tell me what goes wrong here ?

    i pasted your post into chatgpt, it says:


    You?re very close ? the issue is a combo of log base, formula form, and
    how Mercator Y is mapped to pixels. Nothing fundamentally wrong with
    your trig. Let?s untangle it cleanly.

    then it explains a possible error in your formula and suggests the
    workaround

    --
    /-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\
    -=- -=- -=- -=- -=- -=- -=- -=- - -=-
    ........... [ al lavoro ] ...........
    -.-. .... . ... .. ...- .. -. -.-. .- --- -.-. .... . ... .. .--. . .-.
    -.. .- ..-. --- .-. --.. .- - --- .-. --- . .--- ..- ...- . -- . .-.
    -.. .-

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From R.Wieser@3:633/10 to All on Wed Jan 14 14:28:00 2026
    Ammammata,

    i pasted your post into chatgpt, it says:

    You're very close - the issue is a combo of log base,

    Yeah, I noticed that too. log() != log() : loge(), log10(), ln(), lg().

    formula form,

    You got me there I'm afraid. No idea what thats supposed to be about.

    and how Mercator Y is mapped to pixels.

    Really ? I can't imagine.

    Nothing fundamentally wrong
    with your trig. Let's untangle it cleanly.

    then it explains a possible error in your formula and suggests
    the workaround

    Can you post what it said about that explanation and work-around please.

    Regards,
    Rudy Wieser



    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Paul@3:633/10 to All on Wed Jan 14 12:48:20 2026
    On Wed, 1/14/2026 8:28 AM, R.Wieser wrote:
    Ammammata,

    i pasted your post into chatgpt, it says:

    You're very close - the issue is a combo of log base,

    Yeah, I noticed that too. log() != log() : loge(), log10(), ln(), lg().

    formula form,

    You got me there I'm afraid. No idea what thats supposed to be about.

    and how Mercator Y is mapped to pixels.

    Really ? I can't imagine.

    Nothing fundamentally wrong
    with your trig. Let's untangle it cleanly.

    then it explains a possible error in your formula and suggests
    the workaround

    Can you post what it said about that explanation and work-around please.

    Regards,
    Rudy Wieser



    ************ CoPilot Question *************

    The mercator projection of the world globe can be displayed
    on a computer screen. Assume the computer screen is a
    unit square having a diagonal stretching from (0,0) to (1,1).
    Write a C language program that accepts latitude and longitude in signed degrees,
    and computes the location of a dot on the screen in the unit square.

    The interface to the program would say on the command line

    Enter Latitude in degrees:

    Enter Longitude in degrees:

    Your screen data point is at X= Y=

    The program then waits for the next data input without terminating.

    ************ CoPilot Answer *************

    #include <stdio.h>
    #include <math.h>

    /* gcc -lm -o merc.exe merc.c */

    int main(void) {
    double lat, lon;
    const double PI = 3.14159265358979323846;

    while (1) {
    printf("\nEnter Latitude in degrees: ");
    if (scanf("%lf", &lat) != 1) break;

    printf("Enter Longitude in degrees: ");
    if (scanf("%lf", &lon) != 1) break;

    /* Clamp latitude to Mercator limits (~ñ85.05113ø) */
    if (lat > 85.05113) lat = 85.05113;
    if (lat < -85.05113) lat = -85.05113;

    /* Convert longitude to X in [0,1] */
    double x = (lon + 180.0) / 360.0;

    /* Convert latitude to Y in [0,1] using Mercator projection */
    /* Paul: Lang C log() is actually ln(). While Lang C log10() is log base10 */
    double rad = lat * PI / 180.0;
    double y = 0.5 - (log(tan(PI/4.0 + rad/2.0)) / (2.0 * PI));

    printf("Your screen data point is at X=%f Y=%f\n", x, y);
    }

    return 0;
    }
    ************ End CoPilot Answer *************

    It took a bit to convince myself that the equation shown
    in the CoPilot answer was successfully converted to C code.

    *******

    New York : Latitude = 39 (Longitude = -77)

    -- Applying the formula and checking the partial results :

    RadLat = DegToRad(39) -> 0.680952380952381

    Temp = tan(RadLat) + 1/cos(RadLat) -> 2.09728292053088

    log(Temp)/log(10) -> 0.321657020135087

    *******
    The CoPilot program gives

    Enter Latitude in degrees: 39
    Enter Longitude in degrees: -77
    Your screen data point is at X=0.286111 Y=0.382179

    Now, we have to work on our "where is our damn plot origin". Surprise.
    It's not where you think when they wrote the equation. Lets find out.

    Enter Latitude in degrees: -80
    Enter Longitude in degrees: 0
    Your screen data point is at X=0.500000 Y=0.887741

    Enter Latitude in degrees: -50
    Enter Longitude in degrees: 0
    Your screen data point is at X=0.500000 Y=0.660855

    Enter Latitude in degrees: -30
    Enter Longitude in degrees: 0
    Your screen data point is at X=0.500000 Y=0.587425

    Enter Latitude in degrees: 0
    Enter Longitude in degrees: 0
    Your screen data point is at X=0.500000 Y=0.500000

    Enter Latitude in degrees: 30
    Enter Longitude in degrees: 0
    Your screen data point is at X=0.500000 Y=0.412575

    Enter Latitude in degrees: 50
    Enter Longitude in degrees: 0
    Your screen data point is at X=0.500000 Y=0.339145

    Enter Latitude in degrees: 80
    Enter Longitude in degrees: 0
    Your screen data point is at X=0.500000 Y=0.112259

    (0,0) is on the upper left of the unit square.

    Paul

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From R.Wieser@3:633/10 to All on Wed Jan 14 20:44:09 2026
    Paul,

    ************ CoPilot Answer *************
    ...
    double y = 0.5 - (log(tan(PI/4.0 + rad/2.0)) / (2.0 * PI));
    ...
    Enter Latitude in degrees: 39
    Enter Longitude in degrees: -77
    Your screen data point is at X=0.286111 Y=0.382179

    :-) That 0.382179 is 0.06+ larger than what I got from the formule I
    posted - and that one was already *way* to big.

    It looks like the result needs to be in the neighbourhood of 2.3

    If I leave off the "0.5 -" part (likely a pre-inclusion of "half the images height") than I get 0.118, which is still about half of what it needs to be.

    For a test I put 89 degrees latitude into that CoPilot formule I get a
    result of *minus* 0.2662 - which should never happen.

    When I again leave out the "0.5 -" part I get a result of 0.766 - which
    feels way to small.

    I have absolutily no idea what is happening with those formules (I've now
    tried four of them).


    By the way: odd that it has brackets around the "log(...) / (2.0 *PI)" part,
    as if CoPilot isn't sure about if division comes before subtraction. Same
    for the "/ (2.0 * PI)" part.

    Here are the partial results from that CoPilot formule :

    Lat: 39
    Ang: .680952380952381
    Tan: 2.09899066938588
    Log: .741456595562241
    Div: .117959003839447
    Res: .382040996160553

    Regards,
    Rudy Wieser



    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Paul@3:633/10 to All on Wed Jan 14 16:34:36 2026
    On Wed, 1/14/2026 2:44 PM, R.Wieser wrote:

    ************ CoPilot Answer *************
    ...
    double y = 0.5 - (log(tan(PI/4.0 + rad/2.0)) / (2.0 * PI));
    ...
    Enter Latitude in degrees: 39
    Enter Longitude in degrees: -77
    Your screen data point is at X=0.286111 Y=0.382179

    :-) That 0.382179 is 0.06+ larger than what I got from the formule I
    posted - and that one was already *way* to big.

    It looks like the result needs to be in the neighbourhood of 2.3

    If I leave off the "0.5 -" part (likely a pre-inclusion of "half the images height") than I get 0.118, which is still about half of what it needs to be.

    For a test I put 89 degrees latitude into that CoPilot formule I get a
    result of *minus* 0.2662 - which should never happen.

    When I again leave out the "0.5 -" part I get a result of 0.766 - which
    feels way to small.

    I have absolutily no idea what is happening with those formules (I've now tried four of them).


    By the way: odd that it has brackets around the "log(...) / (2.0 *PI)" part, as if CoPilot isn't sure about if division comes before subtraction. Same for the "/ (2.0 * PI)" part.

    Here are the partial results from that CoPilot formule :

    Lat: 39
    Ang: .680952380952381
    Tan: 2.09899066938588
    Log: .741456595562241
    Div: .117959003839447
    Res: .382040996160553

    Regards,
    Rudy Wieser



    The CoPilot formula is capped to the valid range.

    /* Clamp latitude to Mercator limits (approximately plus or minus 85.05113 degrees) */
    if (lat > 85.05113) lat = 85.05113;
    if (lat < -85.05113) lat = -85.05113;

    In scientific endeavor, equations frequently have ranges of validity.
    When doing Spice simulations of transmission lines, some equations are
    only good to a certain cross sectional aspect ratio. Then, a second
    equation covers the next chunk of domain. And so on. Your 89 degree
    attempt, should be a result from 85 degrees, as set by the capping logic.

    The Mercator is clamped, at a point where the exaggeration of size
    has become too absurd. Maybe it is arbitrarily set at 10:1, or it
    could be set at some other value. Greenland should fit into Africa,
    something like 14 times.

    I would have liked to pump data points for an outline map into
    this little project, to see if the projection makes sense, but I could
    not find any hint of available data decks online. I have a box of *punch cards* in the house, with this data on it. Now, where did I leave those ? Hmmm.

    I was doing maps of the earth on a mainframe, and dumping to a line printer (132 columns),
    and that was a long time ago. And that was with the QDGS library. As a 3D model, you could
    set the "eye" in space, and see an ASCII-art diagram of what the map looks like at
    that position. You could model what a space-landing would look like.

    *******

    There are likely to be more than one Mercator projection. I'm not an expert
    in this topic, and just about anything is possible. Trace down the origins
    of the equation you got, and see if the article makes any mention of other
    math formula for it.

    That's why I wanted to plot off a unit square with the world in it,
    just to check that the presentation looks like the map in Wiki.
    This is what CoPilot offered as cites.

    https://hub.arcgis.com/datasets/esri::world-continents/explore <=== 1KB, then froze

    https://www.giss.nasa.gov/tools/panoply/overlays/ <=== Mystery format (binary)
    https://www.giss.nasa.gov/tools/panoply/ (need Java runtime)

    https://ourworldindata.org/grapher/continents-according-to-our-world-in-data ?

    https://geo.malagis.com/global-continent-boundary-datasets-a-comparative-analysis.html <=== poly and shapes

    Looks about as pleasant as yard work.

    Paul

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From R.Wieser@3:633/10 to All on Thu Jan 15 09:57:04 2026
    Paul,

    The CoPilot formula is capped to the valid range.

    /* Clamp latitude to Mercator limits (approximately plus or minus 85.05113 degrees) */
    if (lat > 85.05113) lat = 85.05113;
    if (lat < -85.05113) lat = -85.05113;

    I tested 85 degrees latitude too, which gave a 0.500 result - cutting Russia vertically in two. Hey, when 89 degrees latitude returns something as low
    as 0.766 , what did you expect ?

    I would have liked to pump data points for an outline map into
    this little project, to see if the projection makes sense, but I
    could not find any hint of available data decks online.

    I found a number of Mercator maps (one of them I provided in my initial message), and even a few in .SVG form. Like this one :

    https://mathworld.wolfram.com/MercatorProjection.html

    (Its also the one where I got my initial formule from)

    I also got a few reference lat/lon coordinates :

    https://time-ok.com/coordinates/north-america https://time-ok.com/coordinates/europe

    There are likely to be more than one Mercator projection.

    Not too many, if I may believe Wikipedia :

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

    By the way, I do not see any difference beween the "Mercator = Wright" and "Web Mercator" images.

    That's why I wanted to plot off a unit square with the world in it,
    just to check that the presentation looks like the map in Wiki.

    Thats what I started with (the above links are the result of it). :-)

    This is what CoPilot offered as cites.

    My browser "doesn't do" JS, so no joy on the first two links

    https://ourworldindata.org/grapher/continents-according-to-our-world-in-data

    That one looks to be an Equirectangular projection, and is easy to plot on - lineair in both directions.

    Alas. Although I can access the last webpage, I get 403 status when I try
    to access the webp images.

    Looks about as pleasant as yard work.

    :-) Some people happen to like yard work. But yes, it is tedious. Extra
    fun was gotten when reading that log() != log() .

    Regards,
    Rudy Wieser



    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From R.Wieser@3:633/10 to All on Thu Jan 15 13:43:41 2026
    Further stuff :

    I just thought of drawing latitude lines spaced 10 degrees apart on the
    image I provided, and ran into other problems :

    I had to multiply the formules result by two to get anywhere near a usable value.

    The 10 degree line was drawn below the first line in the image above the equator. Same for the 20 degree line. Only the 30 and 60 degree lines
    landed on a line on the image itself (the second and fourth above the equator).

    Though the 40 degree line now comes rather close to where I expected New
    York to be (which is at 39 degrees latitude), there is no line in the image near it. Huh?

    I don't get it, what are those lines on the image for if not latitudes ? But than again, why are there only 5 lines above the equator in the image, and
    not 7 ?

    Regards,
    Rudy Wieser



    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bob Vloon@3:633/10 to All on Thu Jan 15 12:36:45 2026
    "R.Wieser" <address@is.invalid> writes:

    By the way: odd that it has brackets around the "log(...) / (2.0 *PI)" part, >as if CoPilot isn't sure about if division comes before subtraction. Same >for the "/ (2.0 * PI)" part.

    <pedantic mode>
    It is not sure about anything - it generates text based on statistics. </pedantic mode>

    Sorry for this non-related interruption ;)

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From R.Wieser@3:633/10 to All on Thu Jan 15 14:52:23 2026
    Bob,

    By the way: odd that it has brackets around the "log(...) / (2.0 *PI)"
    part, as if CoPilot isn't sure about if division comes before
    subtraction.
    Same for the "/ (2.0 * PI)" part.

    <pedantic mode>
    It is not sure about anything - it generates text based on statistics. </pedantic mode>

    You know that, I know that. There is no intelligence to be had from AI's.
    :-) :-(

    But that makes it even worse : (all) the people who that that formule was stolen^wtaken^wcopied from where not sure about the order of operations ?

    I can imagine plenty such brackets when trying to teach beginners some math, but not really in source-code like that. Also, too many of a good thing
    can be bad (obsfucating where its actually important).

    Regards,
    Rudy Wieser



    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From J. P. Gilliver@3:633/10 to All on Thu Jan 15 17:25:26 2026
    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 plo
    t
    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_proj
    ection_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.

    --
    J. P. Gilliver. UMRA: 1960/<1985 MB++G()ALIS-Ch++(p)Ar++T+H+Sh0!:`)DNAf

    It has been my experience that folks who have no vices have very few
    virtues
    -- Abraham Lincoln, quoted by Mark Lloyd in alt.windows7.general 2018-12-
    27

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From R.Wieser@3:633/10 to All on Thu Jan 15 21:00:31 2026
    J.P. ,

    First off, FYI, Paul has minimized his posting about the subject to the
    Win10 group only. If you're not there already it might be a good idea to
    take a peek.

    If it _is_ light-source-at-centre, then the Y co-ordinate would just be
    the tangent of the latitude

    Somewhere along the road I had a similar thought. But why than do all the formules I now have (four at the moment) all do a tan() and than wrap that
    up in a log() ? There must be something to it.

    Regards,
    Rudy Wieser



    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From J. P. Gilliver@3:633/10 to All on Thu Jan 15 23:53:57 2026
    On 2026/1/15 20:0:31, R.Wieser wrote:
    J.P. ,

    [John by the way :-) ]

    First off, FYI, Paul has minimized his posting about the subject to the Win10 group only. If you're not there already it might be a good idea to take a peek.

    I replied to the posting I did, thinking I was the only respondent -
    probably in the W7 'group; I saw the other responses when I moved to one
    of the other 'groups, but too late then to amend my post.

    If it _is_ light-source-at-centre, then the Y co-ordinate would just be
    the tangent of the latitude

    Somewhere along the road I had a similar thought. But why than do all the formules I now have (four at the moment) all do a tan() and than wrap that up in a log() ? There must be something to it.

    []

    Indeed! But I can't think what.

    Did you _try_ using just the tangent on a couple of places? Or perhaps
    just a couple of latitudes, to see if the lines come out where they are
    on the plot? You'd probably have to do that in the first place anyway,
    to see what the vertical scale _is_; if doing that for say the ten and
    forty degree lines (assuming that's what the ones on the plot are) gives different scales, then you'd know it isn't just that.


    --
    J. P. Gilliver

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Paul@3:633/10 to All on Fri Jan 16 00:09:03 2026
    On Thu, 1/15/2026 8:52 AM, R.Wieser wrote:
    Bob,

    By the way: odd that it has brackets around the "log(...) / (2.0 *PI)"
    part, as if CoPilot isn't sure about if division comes before
    subtraction.
    Same for the "/ (2.0 * PI)" part.

    <pedantic mode>
    It is not sure about anything - it generates text based on statistics.
    </pedantic mode>

    You know that, I know that. There is no intelligence to be had from AI's. :-) :-(

    But that makes it even worse : (all) the people who that that formule was stolen^wtaken^wcopied from where not sure about the order of operations ?

    I can imagine plenty such brackets when trying to teach beginners some math, but not really in source-code like that. Also, too many of a good thing can be bad (obsfucating where its actually important).

    Regards,
    Rudy Wieser

    There IS an AI trained in symbolic math manipulation,
    and this isn't it :-)

    Paul

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From R.Wieser@3:633/10 to All on Fri Jan 16 07:48:22 2026
    J.P. ,

    [John by the way :-) ]

    John,

    I replied to the posting I did, thinking I was the only respondent -
    probably in the W7 'group; I saw the other responses when I moved
    to one of the other 'groups, but too late then to amend my post.

    There was nothing wrong with your post or suggestion, I just thought that
    you being able to see what others wrote would be beneficial to us both.

    If it _is_ light-source-at-centre, then the Y co-ordinate would just be
    the tangent of the latitude

    But why than do all the formules I now have (four at the moment)
    all do a tan() and than wrap that up in a log() ? There must be
    something to it.
    ...
    Indeed! But I can't think what.

    Same here. But I'm no math wizz.

    Did you _try_ using just the tangent on a couple of places? Or perhaps
    just a couple of latitudes, to see if the lines come out where they are
    on the plot?

    :-) I did so before posting to you and got a rather promising result - on
    the image I provided a link to. But I have no idea if it will also work
    well on an image multiple times as big (where differences will be more prominent).

    iow, I'm only eyeballing the results, and have nothing to numerically
    compare them with. :-|

    You'd probably have to do that in the first place anyway,
    to see what the vertical scale _is_; if doing that for say the ten and
    forty degree lines (assuming that's what the ones on the plot are) gives different scales, then you'd know it isn't just that.

    Yep, thats what I've been doing.

    By the way, the lines on the image are 15 degrees apart horizontally, and
    from it I assume vertically as well. This means that the highest visible
    line is at 75 degrees latitude.

    Ah, I just went back to the wikipedia page* and noticed that the "web Mercator" projection mentions "and clips latitudes to ~85.05? for square presentation". I'm now assuming thats about the image itself. Another assumption is that its also true for the "Mercator = Wright" projection.

    * https://en.wikipedia.org/wiki/List_of_map_projections

    I have to do some more experiments. Though I'm a bit afraid that a tan()-only solution will only be good enough for smaller images, where the differences (compared to the actual formule) are barely noticable. Not
    really what I'm after, but will probably use it as long as I can't get the official formule(s) to work.

    .... But it *does* bother me that I can't get those official ones to work.
    :-(

    Regards,
    Rudy Wieser



    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From R.Wieser@3:633/10 to All on Fri Jan 16 07:56:45 2026
    Paul,

    There IS an AI trained in symbolic math manipulation,
    and this isn't it :-)

    And you asked that AI, which knows nothing about symbolic math manipulation, to help you/me with a formule ? No wonder it doesn't want to work. :-p

    Regards,
    Rudy Wieser



    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Paul@3:633/10 to All on Fri Jan 16 05:08:22 2026
    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

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From J. P. Gilliver@3:633/10 to All on Fri Jan 16 21:59:31 2026
    On 2026/1/16 10:8:22, Paul wrote:

    []

    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/degree
    s-minutes-seconds-to-decimal-degrees

    You used a website to work out 40 + 42/60 + 46/3600? :-)
    []

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

    Paul

    Yes, this has been a puzzle, for what seems like a simple question!

    --
    J. P. Gilliver. UMRA: 1960/<1985 MB++G()ALIS-Ch++(p)Ar++T+H+Sh0!:`)DNAf

    aibohphobia, n., The fear of palindromes.

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Paul@3:633/10 to All on Fri Jan 16 18:23:56 2026
    On Fri, 1/16/2026 4:59 PM, J. P. Gilliver wrote:
    On 2026/1/16 10:8:22, Paul wrote:

    []

    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

    You used a website to work out 40 + 42/60 + 46/3600? :-)
    []

    I am a complex person with special needs :-)

    Paul


    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From R.Wieser@3:633/10 to All on Sat Jan 17 08:19:55 2026
    John,

    Did you _try_ using just the tangent on a couple of places?
    ...
    I have to do some more experiments.

    After having done so, it looks like that

    tan(DegToRad(Latitude)*0.78)\2.53627

    gives a nice result.

    Though I used 75 degree latitude as the reference for the "will the
    calculated lines overlap the ones on the image?" test, causing all lower calculations to be /just/ under the lines on the image.

    Re-doing it using 65 degree latitude as a reference should give a better result (75 degree just above its target, the others just below their target)

    As I mentioned before, good enough to get an indication of the location
    you're looking for, but it can be hundreds of miles to low (or high) ...

    By the way, 0.78 is rather close to Pi/4 . Somehow that raises my suspicion that that is the actual value to be used, and my 0.78 is caused by my "that looks good" eyeballing ...

    Regards,
    Rudy Wieser



    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From R.Wieser@3:633/10 to All on Sat Jan 17 09:11:14 2026
    Paul

    Your coordinates for NYC, where did you get those coords ???

    If you mean 39, -77 its probably from me.

    Looking back in my docs I see I have an image of a globus wit the lat/long lines on it, mentioning 39, -77. The only problem is that it mentions Washington DC, and not New York. I've got no idea how I mixed those two up. My apologies.

    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)

    Is there any chance you can (re)post the used formule (just to be sure I'm using the correct one) and some intermediate results (especially the ones
    fed into the tan() an log() functions) so I can verify what the formule is doing here (and spot my mistake(s)) ?

    Regards,
    Rudy Wieser




    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From J. P. Gilliver@3:633/10 to All on Sat Jan 17 16:28:12 2026
    On 2026/1/17 7:19:55, R.Wieser wrote:
    John,

    Did you _try_ using just the tangent on a couple of places?
    ...
    I have to do some more experiments.

    After having done so, it looks like that

    tan(DegToRad(Latitude)*0.78)\2.53627

    gives a nice result.

    Asssuming DegToRad() just means multiply by pi / 180 ...

    []

    By the way, 0.78 is rather close to Pi/4 . Somehow that raises my suspicion that that is the actual value to be used, and my 0.78 is caused by my "that looks good" eyeballing ...

    Regards,
    Rudy Wieser


    ... then the above simplifies to tan(Latitude*pi*pi/720)\2.53627, and of
    course pi*pi/720 can be given as a constant.

    --
    J. P. Gilliver. UMRA: 1960/<1985 MB++G()ALIS-Ch++(p)Ar++T+H+Sh0!:`)DNAf

    "Tolerating intolerance is not a virtue." - Barry Shein

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Paul@3:633/10 to All on Sat Jan 17 12:11:23 2026
    On Sat, 1/17/2026 3:11 AM, R.Wieser wrote:
    Paul

    Your coordinates for NYC, where did you get those coords ???

    If you mean 39, -77 its probably from me.

    Looking back in my docs I see I have an image of a globus wit the lat/long lines on it, mentioning 39, -77. The only problem is that it mentions Washington DC, and not New York. I've got no idea how I mixed those two up. My apologies.

    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)

    Is there any chance you can (re)post the used formule (just to be sure I'm using the correct one) and some intermediate results (especially the ones
    fed into the tan() an log() functions) so I can verify what the formule is doing here (and spot my mistake(s)) ?

    Regards,
    Rudy Wieser


    The CoPilot response shows its equation here. And this is what
    it used to write the C code for me.

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

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

    Whereas the Wikipedia reference for the same thing is here.
    The USGS equation hides the 2PI part inside its R and it neglects
    to include coordinate correction for plotting purposes. The USGS
    form of the equation shows the "shape of the transform" and is
    not the equation a practitioner needs to implement. The Copilot
    equation delivers a unit square, with the center of the
    map presumably being 0,0 for lat,long. The unit square itself
    has a different origin, like the upper left corner. In any case,
    using your calibrated eyeball, you will be able to figure out
    what additional math is require to fit your plotting scheme.

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

    Mathematics [half way down the page or so...]

    A simple expression for the spherical form of the Mercator projection is:[26]

    [26] https://pubs.usgs.gov/pp/1453/report.pdf (PDF page 228, stamped as "page 218")

    The USGS document on its page, does not note the
    agreed 85.05113 degree cutoff for latitudes (so the "globe"
    is not too messy). The cutoff is encoded in the C code that CoPilot gave me.

    *************************************************************************** #include <stdio.h>
    #include <math.h>

    /* gcc -lm -o merc.exe merc.c */

    int main(void) {
    double lat, lon;
    const double PI = 3.14159265358979323846;

    while (1) {
    printf("\nEnter Latitude in degrees: ");
    if (scanf("%lf", &lat) != 1) break;

    printf("Enter Longitude in degrees: ");
    if (scanf("%lf", &lon) != 1) break;

    /* Clamp latitude to Mercator limits (plus/minus 85.05113 degrees) */
    if (lat > 85.05113) lat = 85.05113;
    if (lat < -85.05113) lat = -85.05113;

    /* Convert longitude to X in [0,1] */
    double x = (lon + 180.0) / 360.0;

    /* Convert latitude to Y in [0,1] using Mercator projection */
    /* The C log function is an ln(), the C log10 function is an log() */

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

    printf("Your screen data point is at X=%f Y=%f\n", x, y);
    }

    return 0;
    }
    ***************************************************************************

    .\merc

    Enter Latitude in degrees: 40.71277778
    Enter Longitude in degrees: -74.00611111
    Your screen data point is at X=0.294427 Y=0.375981

    And then I scaled up my graphic to 10000 x 10000
    and plotted (2944, 3760). I wrote a piece of code
    I call pbmplot.exe and it starts with an empty
    square and adds the datapoints I extracted from the
    Panoply output. The pbm graphics file format is
    dead simple, and the graphics data (one hundred million
    ASCII characters) is output with one printf("%s")
    type statement :-) The format doesn't even need
    <cr><lf> during the data phase, which I find both
    amusing and practical. I bet Notepad would not
    like that file :-) But GIMP opened that file just fine.

    Paul

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From R.Wieser@3:633/10 to All on Sat Jan 17 21:39:11 2026
    John,

    Asssuming DegToRad() just means multiply by pi / 180 ...

    Well, you may use any calculation in there that you want, as long as it does the job. :-) But yes, thats what the/my DegToRad function does.

    ... then the above simplifies to tan(Latitude*pi*pi/720)\2.53627, and
    of course pi*pi/720 can be given as a constant.

    I didn't even think that far. As I said, I'm no math wizz. :-|

    Regards,
    Rudy Wieser




    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)