NewGamePhysics.Mathematics.MercatorProjection Class Reference

Calculate the elliptical mercator projection lat,lon (degrees) to/from x,y ([0,1]). Reference: http://wiki.openstreetmap.org/index.php/Mercator. More...

List of all members.

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.

Detailed Description

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.


Member Function Documentation

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.

Parameters:
lat The latitude in degrees.
Returns:
The map position.

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.

Parameters:
lon The longitude in degrees.
Returns:
The map position.

Definition at line 59 of file MercatorProjection.cs.

00060         {
00061             if ((lon < 0) || (lon > 360.0))
00062             {
00063                 throw new ArgumentOutOfRangeException("lon");
00064             }
00065 
00066             return lon / 360.0;
00067         }

static double NewGamePhysics.Mathematics.MercatorProjection.xToLon ( double  x  )  [static]

Convert a map position [0,1] to longitude [0,360] using the mercator projection.

Parameters:
x The horizontal map position.
Returns:
The longitude in degrees.

Definition at line 105 of file MercatorProjection.cs.

00106         {
00107             if ((x < 0.0) || (x > 1.0))
00108             {
00109                 throw new ArgumentOutOfRangeException("lon");
00110             }
00111 
00112             return x * 360.0;
00113         }

static double NewGamePhysics.Mathematics.MercatorProjection.yToLat ( double  y  )  [static]

Convert [0,1] to latitude [-90,90] using the mercator projection.

Parameters:
y The vertical map position.
Returns:
The latitude in degrees.

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         }


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2