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
11 using Const = Yubeshi.Constants.Wgs84;
\r
15 public class EcefCoordinate
\r
18 private const double a = Const.SemiMajorAxisA;
\r
19 private const double b = Const.SemiMajorAxisB;
\r
20 private const double e1sq = Const.FirstEccentricitySquared;
\r
21 private const double e2sq = Const.SecondEccentricitySquared;
\r
22 private const double pi = Const.Pi;
\r
25 #region constructors
\r
27 public EcefCoordinate(double x, double y, double z)
\r
28 : this(x, y, z, Double.NaN)
\r
32 public EcefCoordinate(double x, double y, double z, double accuracy)
\r
37 Accuracy = accuracy;
\r
60 public double Accuracy
\r
67 #region public methods
\r
68 public GeodeticCoordinate ToGeodeticCoordinate()
\r
71 double lambda = Math.Atan2(Y, X);
\r
72 double p = Math.Sqrt(X * X + Y * Y);
\r
73 double theta = Math.Atan2(Z * a, p * b);
\r
74 double sin = Math.Sin(theta);
\r
75 double cos = Math.Cos(theta);
\r
77 double phi = Math.Atan2(Z + e2sq * b * sin * sin * sin,
\r
78 p - e1sq * a * cos * cos * cos);
\r
79 double sinPhi = Math.Sin(phi);
\r
80 double cosPhi = Math.Cos(phi);
\r
81 double khi = Math.Sqrt(1.0 - e1sq * sinPhi * sinPhi);
\r
86 ht = Z / sinPhi - n * (1.0 - e1sq);
\r
90 ht = p / Math.Cos(phi) - n;
\r
92 Height h = new Height(ht, Height.Base.Wgs84Ellipsoid);
\r
93 return new GeodeticCoordinate(
\r
94 phi * 180 / pi, lambda * 180 / pi, h);
\r