两个坐标之间的地理中点

发布于 2024-10-02 06:48:16 字数 1356 浏览 2 评论 0原文

我一直在使用 Moveable-Type 网站来帮助我进行一些地理坐标计算,它非常有用,但是,我在计算两个坐标之间的中点时遇到了一个错误。我的结果接近预期,但还不够接近:

posA = {47.64570362, -122.14073746}
posB = {47.64316917, -122.14032175}

预期结果(取自活字计算器)= 47°38′40″N, 122°08′26″W = {47.644444, -122.140556}< /code> 我的结果:{49.6054801645915, -122.14052959995759}

这是我的代码:

private Geocoordinate MidPoint(Geocoordinate posA, Geocoordinate posB)
{
   Geocoordinate midPoint = new Geocoordinate();

   double dLon = DegreesToRadians(posB.Longitude - posA.Longitude);
   double Bx = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Cos(dLon);
   double By = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Sin(dLon);

   midPoint.Latitude = RadiansToDegrees(Math.Atan2(Math.Sin(DegreesToRadians(posA.Latitude)) + Math.Sin(DegreesToRadians(posB.Latitude)), 
                Math.Sqrt((Math.Cos(DegreesToRadians(posA.Latitude)) + Bx) * (Math.Cos(DegreesToRadians(posA.Latitude))) + Bx) + By * By));

   midPoint.Longitude = posA.Longitude + RadiansToDegrees(Math.Atan2(By, Math.Cos(DegreesToRadians(posA.Latitude)) + Bx));

   return midPoint;
}

我有几个私有方法可以在度数和弧度之间进行相互转换。 例如,

private double DegreeToRadian(double angle)
{
   return Math.PI * angle / 180.0;
}

我无法弄清楚为什么我的结果与纬度值相差几度。有什么想法吗?

谢谢

I have been using the Moveable-Type website to aid me in some Geocoordinate calcuations and it's been very useful, however, I have a bug in my calculation of the mid-point between two coordinates. My result is close to the expected, but not close enough:

posA = {47.64570362, -122.14073746}
posB = {47.64316917, -122.14032175}

expected result (taken from the movable type calculator) = 47°38′40″N, 122°08′26″W = {47.644444, -122.140556} my result: {49.6054801645915, -122.14052959995759}

Here is my code:

private Geocoordinate MidPoint(Geocoordinate posA, Geocoordinate posB)
{
   Geocoordinate midPoint = new Geocoordinate();

   double dLon = DegreesToRadians(posB.Longitude - posA.Longitude);
   double Bx = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Cos(dLon);
   double By = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Sin(dLon);

   midPoint.Latitude = RadiansToDegrees(Math.Atan2(Math.Sin(DegreesToRadians(posA.Latitude)) + Math.Sin(DegreesToRadians(posB.Latitude)), 
                Math.Sqrt((Math.Cos(DegreesToRadians(posA.Latitude)) + Bx) * (Math.Cos(DegreesToRadians(posA.Latitude))) + Bx) + By * By));

   midPoint.Longitude = posA.Longitude + RadiansToDegrees(Math.Atan2(By, Math.Cos(DegreesToRadians(posA.Latitude)) + Bx));

   return midPoint;
}

I've got a couple of private methods to do the conversion between Degrees and Radians and back.
E.g.

private double DegreeToRadian(double angle)
{
   return Math.PI * angle / 180.0;
}

I can't work out why my results are off by a couple of degrees on the Lat value. Any ideas?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

写给空气的情书 2024-10-09 06:48:16

你把一些括号放错了。我在代码中标记了这个地方。

private Geocoordinate MidPoint(Geocoordinate posA, Geocoordinate posB)
{
   Geocoordinate midPoint = new Geocoordinate();

   double dLon = DegreesToRadians(posB.Longitude - posA.Longitude);
   double Bx = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Cos(dLon);
   double By = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Sin(dLon);

   midPoint.Latitude = RadiansToDegrees(Math.Atan2(
                Math.Sin(DegreesToRadians(posA.Latitude)) + Math.Sin(DegreesToRadians(posB.Latitude)),
                Math.Sqrt(
                    (Math.Cos(DegreesToRadians(posA.Latitude)) + Bx) *
                    (Math.Cos(DegreesToRadians(posA.Latitude)) + Bx) + By * By))); 
                 // (Math.Cos(DegreesToRadians(posA.Latitude))) + Bx) + By * By)); // Your Code

   midPoint.Longitude = posA.Longitude + RadiansToDegrees(Math.Atan2(By, Math.Cos(DegreesToRadians(posA.Latitude)) + Bx));

   return midPoint;
}

You placed some parentheses wrong. I marked the place in the code.

private Geocoordinate MidPoint(Geocoordinate posA, Geocoordinate posB)
{
   Geocoordinate midPoint = new Geocoordinate();

   double dLon = DegreesToRadians(posB.Longitude - posA.Longitude);
   double Bx = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Cos(dLon);
   double By = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Sin(dLon);

   midPoint.Latitude = RadiansToDegrees(Math.Atan2(
                Math.Sin(DegreesToRadians(posA.Latitude)) + Math.Sin(DegreesToRadians(posB.Latitude)),
                Math.Sqrt(
                    (Math.Cos(DegreesToRadians(posA.Latitude)) + Bx) *
                    (Math.Cos(DegreesToRadians(posA.Latitude)) + Bx) + By * By))); 
                 // (Math.Cos(DegreesToRadians(posA.Latitude))) + Bx) + By * By)); // Your Code

   midPoint.Longitude = posA.Longitude + RadiansToDegrees(Math.Atan2(By, Math.Cos(DegreesToRadians(posA.Latitude)) + Bx));

   return midPoint;
}
狼亦尘 2024-10-09 06:48:16

一些方法(例如WGS84 约定)包括地球的扁率。 (至少这里是这么说的

Some methods (eg WGS84 conventions) include oblateness of the earth. (at least that's what it says here)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文