• R/O
  • HTTP
  • SSH
  • HTTPS

yubeshi: Commit

source codes and tests


Commit MetaInfo

Revision91341579334452cf1e6d4ae304d9244781b783c2 (tree)
Time2011-03-01 21:02:33
Authorkimikage <kimikage_ceo@hotm...>
Commiterkimikage

Log Message

平面直角座標への変換の不具合を修正

Change Summary

Incremental Difference

--- a/Yubeshi/Degree.cs
+++ b/Yubeshi/Degree.cs
@@ -106,7 +106,7 @@ namespace Yubeshi
106106 return new Degree(rad * radToDeg);
107107 }
108108
109- public static Degree FromGpsFormat(string angle)
109+ public static Degree FromNmeaFormat(string angle)
110110 {
111111 return FromNmeaFormat(angle, null);
112112 }
@@ -124,14 +124,15 @@ namespace Yubeshi
124124
125125 public override string ToString()
126126 {
127+ double s = Math.Abs(degree * 3600) % 60.0;
127128 if (degree < 0)
128129 {
129- return String.Format("-{0}°{1}′{2}″",
130- -Deg, -Minute, -Second);
130+ return String.Format("-{0}°{1}′{2:G6}″",
131+ -Deg, -Minute, s);
131132 }
132133 else
133134 {
134- return String.Format("{0}°{1}′{2}″", Deg, Minute, Second);
135+ return String.Format("{0}°{1}′{2:G6}″", Deg, Minute, s);
135136 }
136137 }
137138
@@ -139,6 +140,7 @@ namespace Yubeshi
139140 {
140141 return degree.ToString(format);
141142 }
143+
142144 #endregion
143145 }
144146 }
--- a/Yubeshi/Japan/Jpc.cs
+++ b/Yubeshi/Japan/Jpc.cs
@@ -21,15 +21,15 @@ namespace Yubeshi.Japan
2121 private static class MeridianArcConstants
2222 {
2323 public static readonly double[] K = new double[]{
24- 1.0050525018051135299706,
25- -5.063108622326803921017e-3,
26- 1.062759032760013166595e-5,
27- -2.082040715851126522938e-8,
28- 3.933230470035652928709e-11,
29- -7.265236169124544217757e-14,
30- 1.321653368923020906791e-16,
31- -2.376757353699231655954e-19,
32- 4.109419740268720338702e-22
24+ +1.00505250181314665196,
25+ -5.06310862232687815719e-3,
26+ +1.06275903276004425316e-5,
27+ -2.08204071585121779847e-8,
28+ +3.93323047003588273989e-11,
29+ -7.26523616912507470164e-14,
30+ +1.32165336892313669049e-16,
31+ -2.37675735369947451391e-19,
32+ +4.10941974026919833771e-22
3333 };
3434 /*
3535 private static long[] GenerateSquaredBinomial(int length)
@@ -79,8 +79,8 @@ namespace Yubeshi.Japan
7979 #region fields
8080
8181 public static readonly GeodeticCoordinate[] Origins;
82- private const double e = 0.00669438002290069;
83- private const double e2 = 6.7394967754788593e-3;
82+ private const double e = 6.69438002290078733e-3;
83+ private const double e2 = 6.7394967754789579e-3;
8484 private const double m0 = 0.9999;
8585 #endregion
8686
@@ -95,61 +95,49 @@ namespace Yubeshi.Japan
9595 GeodeticCoordinate origin = Origins[(int)number];
9696 double n = GetRadiusOfPrimeVertical(latitude);
9797 double cos = Math.Cos(latitude.Radian);
98- double cos2 = cos * cos;
99- double c = cos2;
10098
10199 double delta = longitude.Radian - origin.Longitude.Radian;
102- double delta2 = delta * delta;
103- double d = delta2;
104100
105101 double t = Math.Tan(latitude.Radian);
106102 double t2 = t * t;
107103 double t4 = t2 * t2;
108104
109- double eta2 = e2 * cos2;
105+ double eta2 = e2 * cos * cos;
110106 double eta4 = eta2 * eta2;
111-
112- double deltaS = GetLengthOfMeridianArc(latitude) -
113- GetLengthOfMeridianArc(origin.Latitude);
114107
115- X = cos * t * d / 2.0;
108+ double cd2 = cos * cos * delta * delta;
109+ double cd = cd2 * t;
116110
117- d *= delta2;
118- c *= cos2;
119- X += c * t * d / 24.0 *
120- (5.0 - t2 + 9.0 * eta2 + 4.0 * eta4);
111+ X = cd / 2.0;
121112
122- d *= delta2;
123- c *= cos2;
124- X -= c * t * d / 720.0 *
125- (-61.0 + 58.0 * t2 -t4 -270.0 * eta2 + 330.0 * t2 * eta2);
113+ cd *= cd2;
114+ X += cd / 24.0 * (5.0 - t2 + 9.0 * eta2 + 4.0 * eta4);
126115
127- d *= delta2;
128- c *= cos2;
129- X -= c * t * d / 40320.0 *
130- (-1385.0 + 3111.0 * t2 - 543.0 * t4 + t4 * t2);
116+ cd *= cd2;
117+ X += cd / 720.0 *
118+ (61.0 - 58.0 * t2 - t4 + 270.0 * eta2 - 330.0 * t2 * eta2);
131119
132- X *= n;
133- X = (X + deltaS) * m0;
120+ cd *= cd2;
121+ X += cd / 40320.0 *
122+ (1385.0 - 3111.0 * t2 + 543.0 * t4 - t4 * t2);
134123
124+ double deltaS = GetLengthOfMeridianArc(latitude) -
125+ GetLengthOfMeridianArc(origin.Latitude);
126+ X = (X * n + deltaS) * m0;
135127
136- c = cos;
137- d = delta;
138128
139- Y = c * d;
129+ cd = cos * delta;
130+ Y = cd;
140131
141- d *= delta2;
142- c *= cos2;
143- Y -= c * d / 6.0 * (-1.0 + t2 - eta2);
132+ cd *= cd2;
133+ Y -= cd / 6.0 * (-1.0 + t2 - eta2);
144134
145- d *= delta2;
146- c *= cos2;
147- Y -= c * d / 120.0 *
135+ cd *= cd2;
136+ Y -= cd / 120.0 *
148137 (-5.0 + 18.0 * t2 - t4 - 14.0 * eta2 + 58.0 * t2 * eta2);
149-
150- d *= delta2;
151- c *= cos2;
152- Y -= c * d / 5040.0 *
138+
139+ cd *= cd2;
140+ Y -= cd / 5040.0 *
153141 (-61.0 + 479.0 * t2 - 179.0 * t4 + t4 * t2);
154142 Y *= n * m0;
155143 }
@@ -210,13 +198,13 @@ namespace Yubeshi.Japan
210198 {
211199 double s = 0;
212200 double phi = latitude.Radian;
213- for (int i = MeridianArcConstants.K.Length -1; i > 0; --i)
201+ double[] k = MeridianArcConstants.K;
202+ for (int i = k.Length - 1; i > 0; --i)
214203 {
215- int j = i + i;
216- s += Math.Sin(j * phi) * MeridianArcConstants.K[i] / j;
204+ int i2 = i + i;
205+ s += k[i] * Math.Sin(i2 * phi) / i2;
217206 }
218- s += phi * MeridianArcConstants.K[0];
219- return s * Constants.SemiMajorAxisA * (1 - e);
207+ return Constants.SemiMajorAxisA * (1.0 - e) * (s + k[0] * phi);
220208 }
221209
222210 public static double GetRadiusOfPrimeVertical(Degree latitude)
--- a/YubeshiTest/DegreeTest.cs
+++ b/YubeshiTest/DegreeTest.cs
@@ -49,5 +49,13 @@ namespace YubeshiTest
4949 d = new Degree(-123, -45, -6);
5050 Assert.AreEqual(-123.751666666666667, (double)d);
5151 }
52+
53+ [Test]
54+ public new void ToString()
55+ {
56+ Assert.AreEqual("123°45′6″", new Degree(123, 45, 6).ToString());
57+ Assert.AreEqual("-123°27′24.12″",
58+ new Degree(-123.4567).ToString());
59+ }
5260 }
5361 }
--- a/YubeshiTest/EcefCoordinateTest.cs
+++ b/YubeshiTest/EcefCoordinateTest.cs
@@ -10,28 +10,26 @@ using System.Collections.Generic;
1010 using System.Text;
1111 using NUnit.Framework;
1212 using Yubeshi;
13+using C = YubeshiTest.SampleCoordinates;
1314
1415 namespace YubeshiTest
1516 {
1617 class EcefCoordinateTest
1718 {
19+
1820 [Test]
1921 public void ToGeodeticCoordinate()
2022 {
21- //35.658611, 139.745556
22- GeodeticCoordinate geo =
23- new GeodeticCoordinate(35.710058, 139.810719, 634.0);
24- EcefCoordinate ecef = new EcefCoordinate(-3961181.33065119,
25- 3346187.6735982029,
26- 3702487.1956870905);
23+ GeodeticCoordinate geo = C.SkyTreeTop;
24+ EcefCoordinate ecef = new EcefCoordinate(-3961181.340,
25+ 3346187.629,
26+ 3702487.226);
2727
2828 GeodeticCoordinate converted = ecef.ToGeodeticCoordinate();
2929
30- Assert.AreEqual(geo.Latitude, converted.Latitude, 1e-9);
31- Assert.AreEqual(geo.Longitude, converted.Longitude, 1e-9);
32- Assert.AreEqual(geo.Altitude, converted.Altitude, 2e-9);
33-
34-
30+ Assert.AreEqual(geo.Latitude, converted.Latitude, 1e-6);
31+ Assert.AreEqual(geo.Longitude, converted.Longitude, 1e-6);
32+ Assert.AreEqual(geo.Altitude, converted.Altitude, 2e-4);
3533
3634 }
3735 }
--- a/YubeshiTest/JapanTest/JpcTest.cs
+++ b/YubeshiTest/JapanTest/JpcTest.cs
@@ -9,6 +9,7 @@ using System;
99 using System.Collections.Generic;
1010 using System.Text;
1111 using NUnit.Framework;
12+using Yubeshi;
1213 using Yubeshi.Japan;
1314 using C = YubeshiTest.SampleCoordinates;
1415
@@ -21,16 +22,16 @@ namespace YubeshiTest.JapanTest
2122 public void LlhToJpc9()
2223 {
2324 Jpc jpc = new Jpc(C.SkyTreeTop, Jpc.System.IX);
24- Assert.AreEqual(-32167.406, jpc.X, 0.1);
25- Assert.AreEqual(-2046.184, jpc.Y, 0.1);
25+ Assert.AreEqual(-32167.4434696, jpc.X, 1e-3);
26+ Assert.AreEqual(-2046.2245495, jpc.Y, 1e-3);
2627 }
2728
2829 [Test]
2930 public void GetLengthOfMeridianArc()
3031 {
3132 Assert.AreEqual(0.0, Jpc.GetLengthOfMeridianArc(0.0));
32- Assert.AreEqual(10001965.7, Jpc.GetLengthOfMeridianArc(90.0), 0.1);
3333 Assert.AreEqual(4984944.4, Jpc.GetLengthOfMeridianArc(45.0), 0.1);
34+ Assert.AreEqual(10001965.7, Jpc.GetLengthOfMeridianArc(90.0), 0.1);
3435 }
3536
3637 }
Show on old repository browser