• R/O
  • HTTP
  • SSH
  • HTTPS

yubeshi: Commit

source codes and tests


Commit MetaInfo

Revision65199477b3d11d012c3483e5f378051042f154b6 (tree)
Time2012-06-07 18:34:33
Authorkimikage <kimikage_ceo@hotm...>
Commiterkimikage

Log Message

一番原点が近い系の取得に対応

Change Summary

Incremental Difference

--- a/Yubeshi/Japan/Jpc.cs
+++ b/Yubeshi/Japan/Jpc.cs
@@ -9,6 +9,7 @@ using System;
99 using System.Collections.Generic;
1010 using System.Text;
1111 using Llh = Yubeshi.GeodeticCoordinate;
12+using Const = Yubeshi.Constants.Grs80;
1213
1314 namespace Yubeshi.Japan
1415 {
@@ -79,8 +80,6 @@ namespace Yubeshi.Japan
7980 #region fields
8081
8182 public static readonly GeodeticCoordinate[] Origins;
82- private const double e = 6.69438002290078733e-3;
83- private const double e2 = 6.7394967754789579e-3;
8483 private const double m0 = 0.9999;
8584 #endregion
8685
@@ -92,6 +91,7 @@ namespace Yubeshi.Japan
9291
9392 public Jpc(Degree latitude, Degree longitude, System number)
9493 {
94+ SystemId = number;
9595 GeodeticCoordinate origin = Origins[(int)number];
9696 double n = GetRadiusOfPrimeVertical(latitude);
9797 double cos = Math.Cos(latitude.Radian);
@@ -102,7 +102,8 @@ namespace Yubeshi.Japan
102102 double t2 = t * t;
103103 double t4 = t2 * t2;
104104
105- double eta2 = e2 * cos * cos;
105+ double eta2 = Const.SecondEccentricitySquared;
106+ eta2 *= cos * cos;
106107 double eta4 = eta2 * eta2;
107108
108109 double cd2 = cos * cos * delta * delta;
@@ -146,6 +147,7 @@ namespace Yubeshi.Japan
146147 {
147148 X = x;
148149 Y = y;
150+ SystemId = System.Unknown;
149151 }
150152
151153 static Jpc()
@@ -189,6 +191,12 @@ namespace Yubeshi.Japan
189191 private set;
190192 }
191193
194+ public System SystemId
195+ {
196+ get;
197+ private set;
198+ }
199+
192200
193201 #endregion
194202
@@ -204,14 +212,43 @@ namespace Yubeshi.Japan
204212 int i2 = i + i;
205213 s += k[i] * Math.Sin(i2 * phi) / i2;
206214 }
207- return Constants.SemiMajorAxisA * (1.0 - e) * (s + k[0] * phi);
215+ return Const.SemiMajorAxisA *
216+ (1.0 - Const.FirstEccentricitySquared) * (s + k[0] * phi);
208217 }
209218
210219 public static double GetRadiusOfPrimeVertical(Degree latitude)
211220 {
212221 double sin = Math.Sin(latitude.Radian);
213- return Constants.SemiMajorAxisA / Math.Sqrt(1 - e * sin * sin);
222+ double r =
223+ Math.Sqrt(1 - Const.FirstEccentricitySquared * sin * sin);
224+ return Const.SemiMajorAxisA / r;
225+ }
226+
227+ public static System GetSystemWithNearestOriginTo(
228+ GeodeticCoordinate coord)
229+ {
230+ System nearestSystem = System.Unknown;
231+ double min = Double.MaxValue;
232+ for (int i = 1; i <= (int)System.XIX; ++i)
233+ {
234+ System s = (System)i;
235+ Jpc c = new Jpc(coord, s);
236+ double d = c.X * c.X + c.Y * c.Y;
237+ if (d < min)
238+ {
239+ min = d;
240+ nearestSystem = s;
241+ }
242+ }
243+ return nearestSystem;
214244 }
245+
246+ public EnuCoordinate ToEnuCoordinate(Height height)
247+ {
248+ GeodeticCoordinate origin = Origins[(int)SystemId];
249+ return new EnuCoordinate(Y, X, height, origin.ToEcefCoordinate());
250+ }
251+
215252 #endregion
216253 }
217254 }
--- a/YubeshiTest/JapanTest/JpcTest.cs
+++ b/YubeshiTest/JapanTest/JpcTest.cs
@@ -15,15 +15,16 @@ using C = YubeshiTest.SampleCoordinates;
1515
1616 namespace YubeshiTest.JapanTest
1717 {
18+ [TestFixture]
1819 class JpcTest
1920 {
2021
2122 [Test]
2223 public void LlhToJpc9()
2324 {
24- Jpc jpc = new Jpc(C.SkyTreeTop, Jpc.System.IX);
25- Assert.AreEqual(-32167.4434696, jpc.X, 1e-3);
26- Assert.AreEqual(-2046.2245495, jpc.Y, 1e-3);
25+ Jpc jpc = new Jpc(C.SkytreeTop, Jpc.System.IX);
26+ Assert.AreEqual(-32158.459, jpc.X, 1e-3);
27+ Assert.AreEqual(-2035.907, jpc.Y, 1e-3);
2728 }
2829
2930 [Test]
@@ -34,5 +35,11 @@ namespace YubeshiTest.JapanTest
3435 Assert.AreEqual(10001965.7, Jpc.GetLengthOfMeridianArc(90.0), 0.1);
3536 }
3637
38+ [Test]
39+ public void GetSystemWithNearestOriginTo()
40+ {
41+ Jpc.System s = Jpc.GetSystemWithNearestOriginTo(C.SkytreeTop);
42+ Assert.AreEqual(Jpc.System.IX, s);
43+ }
3744 }
3845 }
Show on old repository browser