• R/O
  • HTTP
  • SSH
  • HTTPS

yubeshi: Commit

source codes and tests


Commit MetaInfo

Revision30d60baad41909e564da40cd0e3eb993c2784aa7 (tree)
Time2012-06-07 18:32:44
Authorkimikage <kimikage_ceo@hotm...>
Commiterkimikage

Log Message

定数を楕円体モデルごとに整理,Hieghtクラスに対応

Change Summary

Incremental Difference

--- a/Yubeshi/Constants.cs
+++ b/Yubeshi/Constants.cs
@@ -13,13 +13,32 @@ namespace Yubeshi
1313 {
1414 public static class Constants
1515 {
16- #region fields
17- // based on WGS84
18- public const double SemiMajorAxisA = 6378137.00000;
19- public const double SemiMajorAxisB = 6356752.31425;
20- public const double FirstEccentricitySquared = 6.69437999013e-3;
21- public const double SecondEccentricitySquared = 6.73949674226e-3;
22- public const double Pi = 3.1415926535898;
16+ #region type definitions
17+ public static class Wgs84
18+ {
19+ public const double SemiMajorAxisA = 6378137.00000;
20+ public const double SemiMajorAxisB = 6356752.31425;
21+ public const double FirstEccentricitySquared = 6.69437999013e-3;
22+ public const double SecondEccentricitySquared = 6.73949674226e-3;
23+ public const double InverseFlattening = 298.257223563;
24+ public const double Flattening = 3.3528106647474807e-3;
25+ public const double Pi = 3.1415926535898;
26+ public const double SpeedOfLight = 299792458;
27+ }
28+
29+ public static class Grs80
30+ {
31+ public const double SemiMajorAxisA = 6378137.00000;
32+ public const double SemiMajorAxisB = 6356752.31414;
33+ public const double FirstEccentricitySquared = 6.69438002290e-3;
34+ public const double SecondEccentricitySquared = 6.73949677548e-3;
35+ public const double InverseFlattening = 298.257222101;
36+ public const double Flattening = 3.3528106811823189e-3;
37+ }
38+
39+ public static class Bessel
40+ {
41+ }
2342 #endregion
2443 }
2544 }
--- a/Yubeshi/Degree.cs
+++ b/Yubeshi/Degree.cs
@@ -8,6 +8,7 @@
88 using System;
99 using System.Collections.Generic;
1010 using System.Text;
11+using Const = Yubeshi.Constants.Wgs84;
1112
1213 namespace Yubeshi
1314 {
@@ -15,8 +16,8 @@ namespace Yubeshi
1516 {
1617 #region fields
1718 private double degree;
18- private static readonly double degToRad = Constants.Pi / 180.0;
19- private static readonly double radToDeg = 180.0 / Constants.Pi;
19+ private static readonly double degToRad = Const.Pi / 180.0;
20+ private static readonly double radToDeg = 180.0 / Const.Pi;
2021 #endregion
2122
2223 #region constructors
--- a/Yubeshi/EcefCoordinate.cs
+++ b/Yubeshi/EcefCoordinate.cs
@@ -8,17 +8,18 @@
88 using System;
99 using System.Collections.Generic;
1010 using System.Text;
11+using Const = Yubeshi.Constants.Wgs84;
1112
1213 namespace Yubeshi
1314 {
1415 public class EcefCoordinate
1516 {
1617 #region fields
17- private const double a = Constants.SemiMajorAxisA;
18- private const double b = Constants.SemiMajorAxisB;
19- private const double e1sq = Constants.FirstEccentricitySquared;
20- private const double e2sq = Constants.SecondEccentricitySquared;
21- private const double pi = Constants.Pi;
18+ private const double a = Const.SemiMajorAxisA;
19+ private const double b = Const.SemiMajorAxisB;
20+ private const double e1sq = Const.FirstEccentricitySquared;
21+ private const double e2sq = Const.SecondEccentricitySquared;
22+ private const double pi = Const.Pi;
2223 #endregion
2324
2425 #region constructors
@@ -76,10 +77,21 @@ namespace Yubeshi
7677 double phi = Math.Atan2(Z + e2sq * b * sin * sin * sin,
7778 p - e1sq * a * cos * cos * cos);
7879 double sinPhi = Math.Sin(phi);
80+ double cosPhi = Math.Cos(phi);
7981 double khi = Math.Sqrt(1.0 - e1sq * sinPhi * sinPhi);
8082 double n = a / khi;
81- double h = p / Math.Cos(phi) - n;
82- return new GeodeticCoordinate(phi * 180 / pi, lambda * 180 / pi, h);
83+ double ht;
84+ if (cosPhi < 0.5)
85+ {
86+ ht = Z / sinPhi - n * (1.0 - e1sq);
87+ }
88+ else
89+ {
90+ ht = p / Math.Cos(phi) - n;
91+ }
92+ Height h = new Height(ht, Height.Base.Wgs84Ellipsoid);
93+ return new GeodeticCoordinate(
94+ phi * 180 / pi, lambda * 180 / pi, h);
8395 }
8496 #endregion
8597 }
--- a/Yubeshi/EnuCoordinate.cs
+++ b/Yubeshi/EnuCoordinate.cs
@@ -19,12 +19,12 @@ namespace Yubeshi
1919
2020 #region constructors
2121
22- public EnuCoordinate(double e, double n, double u)
22+ public EnuCoordinate(double e, double n, Height u)
2323 : this(e, n, u, null)
2424 {
2525 }
2626
27- public EnuCoordinate(double e, double n, double u,
27+ public EnuCoordinate(double e, double n, Height u,
2828 EcefCoordinate origin)
2929 {
3030 E = e;
--- a/Yubeshi/GeodeticCoordinate.cs
+++ b/Yubeshi/GeodeticCoordinate.cs
@@ -14,10 +14,10 @@ namespace Yubeshi
1414 public class GeodeticCoordinate
1515 {
1616 #region fields
17- private const double a = Constants.SemiMajorAxisA;
18- private const double b = Constants.SemiMajorAxisB;
19- private const double e1sq = Constants.FirstEccentricitySquared;
20- private const double pi = Constants.Pi;
17+ private const double a = Constants.Wgs84.SemiMajorAxisA;
18+ private const double b = Constants.Wgs84.SemiMajorAxisB;
19+ private const double e1sq = Constants.Wgs84.FirstEccentricitySquared;
20+ private const double pi = Constants.Wgs84.Pi;
2121
2222 #endregion
2323 #region constructors
@@ -28,7 +28,7 @@ namespace Yubeshi
2828 }
2929
3030 public GeodeticCoordinate(
31- Degree latitude, Degree longitude, double altitude)
31+ Degree latitude, Degree longitude, Height altitude)
3232 {
3333 Latitude = latitude;
3434 Longitude = longitude;
@@ -39,15 +39,27 @@ namespace Yubeshi
3939 #region properties
4040
4141 /// <summary>
42- /// in Degree
42+ /// geographic latitude in degree
4343 /// </summary>
4444 public Degree Latitude
4545 {
4646 get;
4747 set;
4848 }
49+
50+ /// <summary>
51+ /// geocentric latitude in degree
52+ /// </summary>
53+ public Degree GeocentricLatitude
54+ {
55+ get
56+ {
57+ return Math.Atan((1 - e1sq) * Math.Tan(Latitude.Radian));
58+ }
59+ }
60+
4961 /// <summary>
50- /// in Degree
62+ /// longitude in degree
5163 /// </summary>
5264 public Degree Longitude
5365 {
@@ -56,9 +68,9 @@ namespace Yubeshi
5668 }
5769
5870 /// <summary>
59- /// in metre
71+ /// altitude in metre
6072 /// </summary>
61- public double Altitude
73+ public Height Altitude
6274 {
6375 get;
6476 set;
--- a/YubeshiTest/EcefCoordinateTest.cs
+++ b/YubeshiTest/EcefCoordinateTest.cs
@@ -20,10 +20,10 @@ namespace YubeshiTest
2020 [Test]
2121 public void ToGeodeticCoordinate()
2222 {
23- GeodeticCoordinate geo = C.SkyTreeTop;
24- EcefCoordinate ecef = new EcefCoordinate(-3961181.340,
25- 3346187.629,
26- 3702487.226);
23+ GeodeticCoordinate geo = C.SkytreeTop;
24+ EcefCoordinate ecef = new EcefCoordinate(-3961187.702,
25+ 3346179.551,
26+ 3702497.996);
2727
2828 GeodeticCoordinate converted = ecef.ToGeodeticCoordinate();
2929
@@ -31,6 +31,18 @@ namespace YubeshiTest
3131 Assert.AreEqual(geo.Longitude, converted.Longitude, 1e-6);
3232 Assert.AreEqual(geo.Altitude, converted.Altitude, 2e-4);
3333
34+ // North Pole
35+ geo = new GeodeticCoordinate(90.0, 0.0,
36+ new Height(0, Height.Base.Wgs84Ellipsoid));
37+ ecef = geo.ToEcefCoordinate();
38+ ecef = new EcefCoordinate(0, 0, Constants.Wgs84.SemiMajorAxisB);
39+
40+ converted = ecef.ToGeodeticCoordinate();
41+
42+ Assert.AreEqual(geo.Latitude, converted.Latitude, 1e-6);
43+ Assert.AreEqual(geo.Longitude, converted.Longitude, 1e-6);
44+ Assert.AreEqual(geo.Altitude, converted.Altitude, 2e-4);
45+
3446 }
3547 }
3648 }
--- a/YubeshiTest/EnuCoordinateTest.cs
+++ b/YubeshiTest/EnuCoordinateTest.cs
@@ -20,7 +20,7 @@ namespace YubeshiTest
2020 [Test]
2121 public void ZeroDistance()
2222 {
23- EnuCoordinate enu = new EnuCoordinate(C.SkyTreeTop, C.SkyTreeTop);
23+ EnuCoordinate enu = new EnuCoordinate(C.SkytreeTop, C.SkytreeTop);
2424 Assert.AreEqual(0.0, enu.E);
2525 Assert.AreEqual(0.0, enu.N);
2626 Assert.AreEqual(0.0, enu.U);
@@ -30,7 +30,7 @@ namespace YubeshiTest
3030 public void UpOnly()
3131 {
3232 EnuCoordinate enu = new EnuCoordinate(
33- C.SkyTreeTop, C.SkyTreeBottom);
33+ C.SkytreeTop, C.SkytreeBottom);
3434
3535 Assert.AreEqual(0.0, enu.E, metreError);
3636 Assert.AreEqual(0.0, enu.N, metreError);
@@ -40,7 +40,7 @@ namespace YubeshiTest
4040 [Test]
4141 public void TwoPoints()
4242 {
43- GeodeticCoordinate c1 = C.SkyTreeTop;
43+ GeodeticCoordinate c1 = C.SkytreeTop;
4444 GeodeticCoordinate c2 = C.TokyoTowerTop;
4545 GeodeticCoordinate c0 = new GeodeticCoordinate(
4646 0.5 * (c1.Latitude + c2.Latitude),
@@ -62,16 +62,16 @@ namespace YubeshiTest
6262 // c2->c1 45.965 + 180 deg
6363 // 45.9455 = 0.5 * (45.926 + 45.965)
6464 Assert.AreEqual(45.946, direction, 1.0 / 60.0);
65- Assert.AreEqual(283.0, du, 1e-3);
65+ Assert.AreEqual(289.0, du, 1e-3);
6666 }
6767
6868 [Test]
6969 public void ToEcefCoordinate()
7070 {
7171 EnuCoordinate enu = new EnuCoordinate(
72- C.SkyTreeTop, C.TokyoTowerTop);
72+ C.SkytreeTop, C.TokyoTowerTop);
7373 EcefCoordinate ecef1 = enu.ToEcefCoordinate();
74- EcefCoordinate ecef2 = C.SkyTreeTop.ToEcefCoordinate();
74+ EcefCoordinate ecef2 = C.SkytreeTop.ToEcefCoordinate();
7575
7676 Assert.AreEqual(ecef2.X, ecef1.X, metreError);
7777 Assert.AreEqual(ecef2.Y, ecef1.Y, metreError);
--- a/YubeshiTest/GeodeticCoordinateTest.cs
+++ b/YubeshiTest/GeodeticCoordinateTest.cs
@@ -30,8 +30,6 @@ namespace YubeshiTest
3030 Assert.AreEqual(ecef.Y, converted.Y, 1e-3);
3131 Assert.AreEqual(ecef.Z, converted.Z, 1e-3);
3232
33-
34-
3533 }
3634 }
3735 }
--- a/YubeshiTest/SampleCoordinates.cs
+++ b/YubeshiTest/SampleCoordinates.cs
@@ -14,13 +14,16 @@ namespace YubeshiTest
1414 {
1515 public class SampleCoordinates
1616 {
17- public static readonly GeodeticCoordinate SkyTreeTop =
18- new GeodeticCoordinate(35.710058, 139.810719, 634.0);
17+ public static readonly GeodeticCoordinate SkytreeTop =
18+ new GeodeticCoordinate(35.710139, 139.810833,
19+ new Height(640.0, Height.Base.Geoid));
1920
20- public static readonly GeodeticCoordinate SkyTreeBottom =
21- new GeodeticCoordinate(35.710058, 139.810719, 0.0);
21+ public static readonly GeodeticCoordinate SkytreeBottom =
22+ new GeodeticCoordinate(35.710139, 139.810833,
23+ new Height(6.0, Height.Base.Geoid));
2224
2325 public static readonly GeodeticCoordinate TokyoTowerTop =
24- new GeodeticCoordinate(35.658611, 139.745556, 351.0);
26+ new GeodeticCoordinate(35.658611, 139.745556,
27+ new Height(351.0, Height.Base.Geoid));
2528 }
2629 }
Show on old repository browser