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 EcefCoordinate
\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 e2sq = Constants.SecondEccentricitySquared;
\r
21 private const double pi = Constants.Pi;
\r
24 #region constructors
\r
26 public EcefCoordinate(double x, double y, double z)
\r
27 : this(x, y, z, Double.NaN)
\r
31 public EcefCoordinate(double x, double y, double z, double accuracy)
\r
36 Accuracy = accuracy;
\r
42 /// <param name="x">ECEF X coordinate in cm</param>
\r
43 /// <param name="y">ECEF Y coordinate in cm</param>
\r
44 /// <param name="z">ECEF Z coordinate in cm</param>
\r
45 /// <param name="accuracy">3D Position Accuracy Estimate in cm</param>
\r
46 public EcefCoordinate(int x, int y, int z, uint accuracy)
\r
47 : this(x * 0.01, y * 0.01, z * 0.01, accuracy * 0.01)
\r
71 public double Accuracy
\r
78 #region public methods
\r
79 public GeodeticCoordinate ToGeodeticCoordinate()
\r
82 double lambda = Math.Atan2(Y, X);
\r
83 double p = Math.Sqrt(X * X + Y * Y);
\r
84 double theta = Math.Atan2(Z * a, p * b);
\r
85 double sin = Math.Sin(theta);
\r
86 double cos = Math.Cos(theta);
\r
88 double phi = Math.Atan2(Z + e2sq * b * sin * sin * sin,
\r
89 p - e1sq * a * cos * cos * cos);
\r
90 double sinPhi = Math.Sin(phi);
\r
91 double khi = Math.Sqrt(1.0 - e1sq * sinPhi * sinPhi);
\r
93 double h = p / Math.Cos(phi) - n;
\r
94 return new GeodeticCoordinate(phi * 180 / pi, lambda * 180 / pi, h);
\r