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
#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
\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
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
{\r
X = x;\r
Y = y;\r
+ SystemId = System.Unknown;\r
}\r
\r
static Jpc()\r
private set;\r
}\r
\r
+ public System SystemId\r
+ {\r
+ get;\r
+ private set;\r
+ }\r
+\r
\r
#endregion\r
\r
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
\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
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