OSDN Git Service

一番原点が近い系の取得に対応
authorkimikage <kimikage_ceo@hotmail.com>
Thu, 7 Jun 2012 09:34:33 +0000 (18:34 +0900)
committerkimikage <kimikage_ceo@hotmail.com>
Thu, 7 Jun 2012 09:34:33 +0000 (18:34 +0900)
Yubeshi/Japan/Jpc.cs
YubeshiTest/JapanTest/JpcTest.cs

index 81af1b4..548aa6a 100755 (executable)
@@ -9,6 +9,7 @@ using System;
 using System.Collections.Generic;\r
 using System.Text;\r
 using Llh = Yubeshi.GeodeticCoordinate;\r
+using Const = Yubeshi.Constants.Grs80;\r
 \r
 namespace Yubeshi.Japan\r
 {\r
@@ -79,8 +80,6 @@ namespace Yubeshi.Japan
         #region fields\r
 \r
         public static readonly GeodeticCoordinate[] Origins;\r
-        private const double e = 6.69438002290078733e-3;\r
-        private const double e2 = 6.7394967754789579e-3;\r
         private const double m0 = 0.9999;\r
         #endregion\r
 \r
@@ -92,6 +91,7 @@ namespace Yubeshi.Japan
 \r
         public Jpc(Degree latitude, Degree longitude, System number)\r
         {\r
+            SystemId = number;\r
             GeodeticCoordinate origin = Origins[(int)number];\r
             double n = GetRadiusOfPrimeVertical(latitude);\r
             double cos = Math.Cos(latitude.Radian);\r
@@ -102,7 +102,8 @@ namespace Yubeshi.Japan
             double t2 = t * t;\r
             double t4 = t2 * t2;\r
 \r
-            double eta2 = e2 * cos * cos;\r
+            double eta2 = Const.SecondEccentricitySquared;\r
+            eta2 *= cos * cos;\r
             double eta4 = eta2 * eta2;\r
 \r
             double cd2 = cos * cos * delta * delta;\r
@@ -146,6 +147,7 @@ namespace Yubeshi.Japan
         {\r
             X = x;\r
             Y = y;\r
+            SystemId = System.Unknown;\r
         }\r
 \r
         static Jpc()\r
@@ -189,6 +191,12 @@ namespace Yubeshi.Japan
             private set;\r
         }\r
 \r
+        public System SystemId\r
+        {\r
+            get;\r
+            private set;\r
+        }\r
+\r
 \r
         #endregion\r
 \r
@@ -204,14 +212,43 @@ namespace Yubeshi.Japan
                 int i2 = i + i;\r
                 s += k[i] * Math.Sin(i2 * phi) / i2;\r
             }\r
-            return Constants.SemiMajorAxisA * (1.0 - e) * (s + k[0] * phi);\r
+            return Const.SemiMajorAxisA * \r
+                    (1.0 - Const.FirstEccentricitySquared) * (s + k[0] * phi);\r
         }\r
 \r
         public static double GetRadiusOfPrimeVertical(Degree latitude)\r
         {\r
             double sin = Math.Sin(latitude.Radian);\r
-            return Constants.SemiMajorAxisA / Math.Sqrt(1 - e * sin * sin);\r
+            double r = \r
+                    Math.Sqrt(1 -  Const.FirstEccentricitySquared * sin * sin);\r
+            return Const.SemiMajorAxisA / r;\r
+        }\r
+\r
+        public static System GetSystemWithNearestOriginTo(\r
+                                                    GeodeticCoordinate coord)\r
+        {\r
+            System nearestSystem = System.Unknown;\r
+            double min = Double.MaxValue;\r
+            for (int i = 1; i <= (int)System.XIX; ++i)\r
+            {\r
+                System s = (System)i;\r
+                Jpc c = new Jpc(coord, s);\r
+                double d = c.X * c.X + c.Y * c.Y;\r
+                if (d < min)\r
+                {\r
+                    min = d;\r
+                    nearestSystem = s;\r
+                }\r
+            }\r
+            return nearestSystem;\r
         }\r
+\r
+        public EnuCoordinate ToEnuCoordinate(Height height)\r
+        {\r
+            GeodeticCoordinate origin = Origins[(int)SystemId];\r
+            return new EnuCoordinate(Y, X, height, origin.ToEcefCoordinate());\r
+        }\r
+\r
         #endregion\r
     }\r
 }\r
index 62b996e..88d0d7f 100755 (executable)
@@ -15,15 +15,16 @@ using C = YubeshiTest.SampleCoordinates;
 \r
 namespace YubeshiTest.JapanTest\r
 {\r
+    [TestFixture]\r
     class JpcTest\r
     {\r
 \r
         [Test]\r
         public void LlhToJpc9()\r
         {\r
-            Jpc jpc = new Jpc(C.SkyTreeTop, Jpc.System.IX);\r
-            Assert.AreEqual(-32167.4434696, jpc.X, 1e-3);\r
-            Assert.AreEqual(-2046.2245495, jpc.Y, 1e-3);\r
+            Jpc jpc = new Jpc(C.SkytreeTop, Jpc.System.IX);\r
+            Assert.AreEqual(-32158.459, jpc.X, 1e-3);\r
+            Assert.AreEqual(-2035.907, jpc.Y, 1e-3);\r
         }\r
 \r
         [Test]\r
@@ -34,5 +35,11 @@ namespace YubeshiTest.JapanTest
             Assert.AreEqual(10001965.7, Jpc.GetLengthOfMeridianArc(90.0), 0.1);\r
         }\r
 \r
+        [Test]\r
+        public void GetSystemWithNearestOriginTo()\r
+        {\r
+            Jpc.System s = Jpc.GetSystemWithNearestOriginTo(C.SkytreeTop);\r
+            Assert.AreEqual(Jpc.System.IX, s);\r
+        }\r
     }\r
 }\r