> So, I've got this function that projects a latitude and longitude
> into MS Virtual Earth's projection/coord system, in meters. I'm
> trying to write the reverse of it, to convert the meters back into
> lat/long. What I'm stuck on is reversing this:
>
> $y = 0.5 - log((1 + sin($latitude * $pi / 180)) / (1 - sin
> ($latitude * $pi / 180))) / (4 * $pi);
>
> $latitude's the incoming latitude, $pi is 3.14159..., and $y is the
> result in meters
>
> I need to solve for $latitude, since I'll want to be starting with $y.
>
> Any idea? :)
>
> Furthest I've gotten is here:
>
> -$e ** (($y - 0.5) * 4 * $pi) = (1 + sin($latitude * $pi /
> 180)) / (1 - sin($latitude * $pi / 180));
>
Is there anyone on this list with the math chops to help out? Can't
promise fame or riches, but can offer eternal gratitude and a bevvy
or two.
R.
Notes:
[A] x = e^y .... y = ln(x)
[B] x = sin(y) .... y = arcsin(x)
Let L = latitude * ( pi / 180 ) ... i.e. latitude expressed as radians
So starting with your initial equation:
[0]
Y = 0.5 - LN [ ( 1 + SIN(L) ) / ( 1 - SIN (L) ) ] / ( 4 * pi )
[1]
4 * pi * Y - 0.5 = LN[ ( 1 + SIN(L) ) / ( 1 - SIN (L) ) ]
Let Z = 4 * pi * Y - 0.5
[2]
Z = LN[ ( 1 + SIN(L) ) / ( 1 - SIN (L) ) ]
using rule [A]
[3]
e^Z = ( 1 + SIN(L) ) / ( 1 - SIN(L) )
[4]
(1 - SIN(L) ) * e ^ Z = 1 + SIN(L)
[5]
e^Z - e^Z * SIN(L) = 1 + SIN(L)
[6]
e^Z - 1 = SIN(L) + e^Z * SIN(L)
[7]
e^Z - 1 = SIN(L) * (1 + e^Z)
[8]
SIN(L) = ( e^Z + 1 ) / ( e^Z - 1 )
[9]
L = ARCSIN[ ( e^Z + 1 ) / ( e^Z - 1 ) ]
That certainly looks about right, symmetry wise. It's then only a
matter of plugging back in Z into the equation, and undoing the
radians / degree conversion.
Or it could be all crap -- I haven't done any serious math in
decades ;-)
Regards, etc...
R.