Mercator map projection logic conflict
-
22-04-2021 - |
Question
I'm looking for an explanation on why there are 2 different mercator formulas discussed on these sites.
I understand this to be the correct mercator projection algorithm:
http://en.wikipedia.org/wiki/Mercator_projection
y = ln|sec(lat) + tan(lat)|
However, this site refers to something completely different: http://wiki.openstreetmap.org/wiki/Mercator
#include <math.h>
double lat2y(double a) { return 180/M_PI * log(tan(M_PI/4+a*(M_PI/180)/2)); }
Any ideas?
La solution
Both formulas are equal.
sec(x) + tan(x) = [ 1 + sin(x) ] / cos(x)
tan(pi/4 + x/2) = sin(pi/4 + x/2) / cos(pi/4 + x/2) =
= [cos(x/2) + sin(x/2)] / [cos(x/2) - sin(x/2)] =
= [cos(x/2) + sin(x/2)]^2 / [cos(x/2) - sin(x/2)] / [cos(x/2) + sin(x/2)] =
= [1 + 2*cos(x/2)*sin(x/2)] / [cos^2(x/2) - sin^2(x/2)] =
= [1 + sin(x)] / cos(x)
The latter formula is more convenient for numerical calculations, because it involves the computation of the trigonometric function only once.