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
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 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
************ 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;
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.
There are likely to be more than one Mercator projection.
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://ourworldindata.org/grapher/continents-according-to-our-world-in-data
Looks about as pleasant as yard work.
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.
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>
Hello all,t
I have a world map using the Mercator projection, and would like to plo
some stuff on it using Latitude and Longitude.the
The problem is that I can't seem to get the formule I found to spit out
correct value for Y.ection_Square.JPG/250px-Mercator_projection_Square.JPG
-- The map :
https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Mercator_proj
-- The formula :
Y = ln( tan(latitude) + sec(latitude) )
where "ln(...)" is log(...) / log(10)
... at least, that is what I could google about it.
If it _is_ light-source-at-centre, then the Y co-ordinate would just be
the tangent of the latitude
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.
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
[John by the way :-) ]
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
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.
There IS an AI trained in symbolic math manipulation,
and this isn't it :-)
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.
Your coordinates for NYC, where did you get those coords ???s-minutes-seconds-to-decimal-degrees
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
I think the equation is pretty close. But I'm not happy that
there is an error still there.
Paul
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? :-)
[]
...Did you _try_ using just the tangent on a couple of places?
I have to do some more experiments.
Your coordinates for NYC, where did you get those coords ???
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)
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.
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
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
Asssuming DegToRad() just means multiply by pi / 180 ...
... then the above simplifies to tan(Latitude*pi*pi/720)\2.53627, and
of course pi*pi/720 can be given as a constant.
| Sysop: | Tetrazocine |
|---|---|
| Location: | Melbourne, VIC, Australia |
| Users: | 15 |
| Nodes: | 8 (0 / 8) |
| Uptime: | 173:04:38 |
| Calls: | 188 |
| Files: | 21,502 |
| Messages: | 80,021 |