From: kimikage Date: Thu, 7 Jun 2012 09:34:33 +0000 (+0900) Subject: 一番原点が近い系の取得に対応 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=65199477b3d11d012c3483e5f378051042f154b6;p=yubeshi%2Fyubeshi.git 一番原点が近い系の取得に対応 --- diff --git a/Yubeshi/Japan/Jpc.cs b/Yubeshi/Japan/Jpc.cs index 81af1b4..548aa6a 100755 --- a/Yubeshi/Japan/Jpc.cs +++ b/Yubeshi/Japan/Jpc.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Text; using Llh = Yubeshi.GeodeticCoordinate; +using Const = Yubeshi.Constants.Grs80; namespace Yubeshi.Japan { @@ -79,8 +80,6 @@ namespace Yubeshi.Japan #region fields public static readonly GeodeticCoordinate[] Origins; - private const double e = 6.69438002290078733e-3; - private const double e2 = 6.7394967754789579e-3; private const double m0 = 0.9999; #endregion @@ -92,6 +91,7 @@ namespace Yubeshi.Japan public Jpc(Degree latitude, Degree longitude, System number) { + SystemId = number; GeodeticCoordinate origin = Origins[(int)number]; double n = GetRadiusOfPrimeVertical(latitude); double cos = Math.Cos(latitude.Radian); @@ -102,7 +102,8 @@ namespace Yubeshi.Japan double t2 = t * t; double t4 = t2 * t2; - double eta2 = e2 * cos * cos; + double eta2 = Const.SecondEccentricitySquared; + eta2 *= cos * cos; double eta4 = eta2 * eta2; double cd2 = cos * cos * delta * delta; @@ -146,6 +147,7 @@ namespace Yubeshi.Japan { X = x; Y = y; + SystemId = System.Unknown; } static Jpc() @@ -189,6 +191,12 @@ namespace Yubeshi.Japan private set; } + public System SystemId + { + get; + private set; + } + #endregion @@ -204,14 +212,43 @@ namespace Yubeshi.Japan int i2 = i + i; s += k[i] * Math.Sin(i2 * phi) / i2; } - return Constants.SemiMajorAxisA * (1.0 - e) * (s + k[0] * phi); + return Const.SemiMajorAxisA * + (1.0 - Const.FirstEccentricitySquared) * (s + k[0] * phi); } public static double GetRadiusOfPrimeVertical(Degree latitude) { double sin = Math.Sin(latitude.Radian); - return Constants.SemiMajorAxisA / Math.Sqrt(1 - e * sin * sin); + double r = + Math.Sqrt(1 - Const.FirstEccentricitySquared * sin * sin); + return Const.SemiMajorAxisA / r; + } + + public static System GetSystemWithNearestOriginTo( + GeodeticCoordinate coord) + { + System nearestSystem = System.Unknown; + double min = Double.MaxValue; + for (int i = 1; i <= (int)System.XIX; ++i) + { + System s = (System)i; + Jpc c = new Jpc(coord, s); + double d = c.X * c.X + c.Y * c.Y; + if (d < min) + { + min = d; + nearestSystem = s; + } + } + return nearestSystem; } + + public EnuCoordinate ToEnuCoordinate(Height height) + { + GeodeticCoordinate origin = Origins[(int)SystemId]; + return new EnuCoordinate(Y, X, height, origin.ToEcefCoordinate()); + } + #endregion } } diff --git a/YubeshiTest/JapanTest/JpcTest.cs b/YubeshiTest/JapanTest/JpcTest.cs index 62b996e..88d0d7f 100755 --- a/YubeshiTest/JapanTest/JpcTest.cs +++ b/YubeshiTest/JapanTest/JpcTest.cs @@ -15,15 +15,16 @@ using C = YubeshiTest.SampleCoordinates; namespace YubeshiTest.JapanTest { + [TestFixture] class JpcTest { [Test] public void LlhToJpc9() { - Jpc jpc = new Jpc(C.SkyTreeTop, Jpc.System.IX); - Assert.AreEqual(-32167.4434696, jpc.X, 1e-3); - Assert.AreEqual(-2046.2245495, jpc.Y, 1e-3); + Jpc jpc = new Jpc(C.SkytreeTop, Jpc.System.IX); + Assert.AreEqual(-32158.459, jpc.X, 1e-3); + Assert.AreEqual(-2035.907, jpc.Y, 1e-3); } [Test] @@ -34,5 +35,11 @@ namespace YubeshiTest.JapanTest Assert.AreEqual(10001965.7, Jpc.GetLengthOfMeridianArc(90.0), 0.1); } + [Test] + public void GetSystemWithNearestOriginTo() + { + Jpc.System s = Jpc.GetSystemWithNearestOriginTo(C.SkytreeTop); + Assert.AreEqual(Jpc.System.IX, s); + } } }