Calculate the elliptical mercator projection lat,lon (degrees) to/from x,y ([0,1]). Reference: http://wiki.openstreetmap.org/index.php/Mercator. More...
Static Public Member Functions | |
| static double | lonToX (double lon) |
| Convert longitude [0,360] to [0,1] using the mercator projection. | |
| static double | latToY (double lat) |
| Convert latitude [-90.0,90] to a map position [0,1] using the mercator projection. For angles close to the poles (1 degree) an approximation is used. | |
| static double | xToLon (double x) |
| Convert a map position [0,1] to longitude [0,360] using the mercator projection. | |
| static double | yToLat (double y) |
| Convert [0,1] to latitude [-90,90] using the mercator projection. | |
Calculate the elliptical mercator projection lat,lon (degrees) to/from x,y ([0,1]). Reference: http://wiki.openstreetmap.org/index.php/Mercator.
Definition at line 16 of file MercatorProjection.cs.
| static double NewGamePhysics.Mathematics.MercatorProjection.latToY | ( | double | lat | ) | [static] |
Convert latitude [-90.0,90] to a map position [0,1] using the mercator projection. For angles close to the poles (1 degree) an approximation is used.
| lat | The latitude in degrees. |
Definition at line 76 of file MercatorProjection.cs.
00077 { 00078 if ((lat < -90.0) || (lat > 90.0)) 00079 { 00080 throw new ArgumentOutOfRangeException("lat"); 00081 } 00082 00083 // Limit angles close to poles 00084 lat = Math.Min(89.0, Math.Max(lat, -89.0)); 00085 00086 // Mercator calculation 00087 double phi = DegToRad(lat); 00088 double sinphi = Math.Sin(phi); 00089 double con = Eccentricity * sinphi; 00090 con = Math.Pow(((1.0 - con) / (1.0 + con)), 0.5 * Eccentricity); 00091 double ts = Math.Tan(0.5 * ((Math.PI * 0.5) - phi)) / con; 00092 double y = -Math.Log(ts) * 0.5; 00093 y += 1.0; 00094 y *= 0.5; 00095 y = Math.Min(1.0, Math.Max(y, 0.0)); 00096 return y; 00097 }
| static double NewGamePhysics.Mathematics.MercatorProjection.lonToX | ( | double | lon | ) | [static] |
Convert longitude [0,360] to [0,1] using the mercator projection.
| lon | The longitude in degrees. |
Definition at line 59 of file MercatorProjection.cs.
| static double NewGamePhysics.Mathematics.MercatorProjection.xToLon | ( | double | x | ) | [static] |
Convert a map position [0,1] to longitude [0,360] using the mercator projection.
| x | The horizontal map position. |
Definition at line 105 of file MercatorProjection.cs.
| static double NewGamePhysics.Mathematics.MercatorProjection.yToLat | ( | double | y | ) | [static] |
Convert [0,1] to latitude [-90,90] using the mercator projection.
| y | The vertical map position. |
Definition at line 121 of file MercatorProjection.cs.
00122 { 00123 if ((y < 0.0) || (y > 1.0)) 00124 { 00125 throw new ArgumentOutOfRangeException("lon"); 00126 } 00127 00128 double ts = Math.Exp(-y); 00129 double phi = PiHalf - 2 * Math.Atan(ts); 00130 double dphi = 1.0; 00131 int i = 0; 00132 while ((Math.Abs(dphi) > 0.000000001) && (i < 15)) 00133 { 00134 double c = Eccentricity * Math.Sin(phi); 00135 dphi = PiHalf - 2 * Math.Atan(ts * Math.Pow((1.0 - c) / (1.0 + c), 0.5 * Eccentricity)) - phi; 00136 phi += dphi; 00137 i++; 00138 } 00139 return RadToDeg(phi); 00140 }
1.6.2