4 * This software is distributed under a zlib-style license.
\r
5 * See license.txt for more information.
\r
9 using System.Collections.Generic;
\r
14 public class GeodeticCoordinate
\r
17 private const double a = Constants.SemiMajorAxisA;
\r
18 private const double b = Constants.SemiMajorAxisB;
\r
19 private const double e1sq = Constants.FirstEccentricitySquared;
\r
20 private const double pi = Constants.Pi;
\r
23 #region constructors
\r
25 public GeodeticCoordinate(double latitude, double longitude)
\r
26 : this(latitude, longitude, Double.NaN)
\r
30 public GeodeticCoordinate(double latitude, double longitude, double altitude)
\r
32 Latitude = latitude;
\r
33 Longitude = longitude;
\r
34 Altitude = altitude;
\r
37 public GeodeticCoordinate(string latitude, string ns,
\r
38 string longitude, string ew)
\r
40 decimal latRaw = Decimal.Parse(latitude);
\r
41 decimal lngRaw = Decimal.Parse(longitude);
\r
42 decimal lat = Math.Floor(latRaw / 100m) + (latRaw % 100m) / 60m;
\r
43 decimal lng = Math.Floor(lngRaw / 100m) + (lngRaw % 100m) / 60m;
\r
44 Latitude = (double)((ns == "S") ? -lat : lat);
\r
45 Longitude = (double)((ns == "W") ? -lng : lng);
\r
46 Altitude = Double.NaN;
\r
55 public double Latitude
\r
63 public double Longitude
\r
72 public double Altitude
\r
79 #region public method
\r
80 public EcefCoordinate ToEcefCoordinate()
\r
82 double h = Double.IsNaN(Altitude) ? 0 : Altitude;
\r
83 double sinPhi = Math.Sin(Latitude * pi / 180.0);
\r
84 double cosPhi = Math.Cos(Latitude * pi / 180.0);
\r
85 double khi = Math.Sqrt(1.0 - e1sq * sinPhi * sinPhi);
\r
87 double r = (n + h) * cosPhi;
\r
88 double x = r * Math.Cos(Longitude * pi / 180);
\r
89 double y = r * Math.Sin(Longitude * pi / 180);
\r
90 double z = (n * (1 - e1sq) + h) * sinPhi;
\r
91 return new EcefCoordinate(x, y, z);
\r
97 #region private methods
\r