【求助】求一个函数的反向函数(200)

狂迷

Unregistered / Unconfirmed
GUEST, unregistred user!
下面是一个跟据纬度计算座标的函数(分别有Delphi和C两个版本的实现代码),现在需要一个通过坐标和放大倍数反算纬度的函数(这个函数的反向函数)。我数学不行,不会写,请大家帮帮忙。Delphi 版代码: function GetY(Lat: Extended
Zoom: Integer): integer
var MaxLat, phi, Res, maxTileY: Extended
begin MaxLat := PI
if (lat > 90) then lat := lat - 180
if (lat < -90) then lat := lat + 180
// 角度转孤度 phi := PI * lat / 180
res := 0.5 * Ln((1 + Sin(phi)) / (1 - Sin(phi)))
maxTileY := Power(2, zoom)
result := Floor(((1 - res / maxlat) / 2) * (maxTileY))
end;C 版代码:double GetY(double Lat, int Zoom){ double MaxLat, phi, Res, maxTileY
int result
MaxLat = PI
if (lat > 90) lat = lat - 180
if (lat < -90) lat := lat + 180
// 角度转孤度 phi = PI * lat / 180
res = 0.5 * Log((1 + Sin(phi)) / (1 - Sin(phi)))
maxTileY = Pow(2, zoom)
result := (int)(((1 - res / maxlat) / 2) * (maxTileY))
return(result);}
 
Z

znxia

Unregistered / Unconfirmed
GUEST, unregistred user!
主要就3行需要处理 res := 0.5 * Ln((1 + Sin(phi)) / (1 - Sin(phi)))
maxTileY := Power(2, zoom)
result := Floor(((1 - res / maxlat) / 2) * (maxTileY));-----------------1> ==> 2*res = Ln((1 + Sin(phi)) / (1 - Sin(phi))) ==> Exp(2*Res) = (1 + Sin(phi)) / (1 - Sin(phi)) 假设X = Sin(phi),你可以计算出X吧,然后根据ArcSin,计算出phi2> zoom = log2(maxTileY)3>不需要解释了。
 

狂迷

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢!反推出来的: function TileToLatitude(Y: Integer
zoom: integer): Extended
const MAX_LATITUDE = Pi
var MaxTileY: Extended
MercatorY, res, E: Extended
begin MaxTileY := Power(2, zoom)
MercatorY := TileY
res := MAX_LATITUDE * (1 - 2 * MercatorY / MaxTileY)
E := Exp(2 * res)
E := (E - 1) / (E + 1)
E := E / Sqrt(1 - E * E)
Result := ArcTan(E) * 180 / Pi
end;
 

Similar threads

顶部