1. <small id='5FiKW'></small><noframes id='5FiKW'>

      <bdo id='5FiKW'></bdo><ul id='5FiKW'></ul>
    <legend id='5FiKW'><style id='5FiKW'><dir id='5FiKW'><q id='5FiKW'></q></dir></style></legend>
  2. <tfoot id='5FiKW'></tfoot>

      <i id='5FiKW'><tr id='5FiKW'><dt id='5FiKW'><q id='5FiKW'><span id='5FiKW'><b id='5FiKW'><form id='5FiKW'><ins id='5FiKW'></ins><ul id='5FiKW'></ul><sub id='5FiKW'></sub></form><legend id='5FiKW'></legend><bdo id='5FiKW'><pre id='5FiKW'><center id='5FiKW'></center></pre></bdo></b><th id='5FiKW'></th></span></q></dt></tr></i><div id='5FiKW'><tfoot id='5FiKW'></tfoot><dl id='5FiKW'><fieldset id='5FiKW'></fieldset></dl></div>

    1. 两个坐标之间的地理中点

      Geographic Midpoint between two coordinates(两个坐标之间的地理中点)

          <i id='mdsPY'><tr id='mdsPY'><dt id='mdsPY'><q id='mdsPY'><span id='mdsPY'><b id='mdsPY'><form id='mdsPY'><ins id='mdsPY'></ins><ul id='mdsPY'></ul><sub id='mdsPY'></sub></form><legend id='mdsPY'></legend><bdo id='mdsPY'><pre id='mdsPY'><center id='mdsPY'></center></pre></bdo></b><th id='mdsPY'></th></span></q></dt></tr></i><div id='mdsPY'><tfoot id='mdsPY'></tfoot><dl id='mdsPY'><fieldset id='mdsPY'></fieldset></dl></div>
        1. <tfoot id='mdsPY'></tfoot>
                <bdo id='mdsPY'></bdo><ul id='mdsPY'></ul>
                  <tbody id='mdsPY'></tbody>
                <legend id='mdsPY'><style id='mdsPY'><dir id='mdsPY'><q id='mdsPY'></q></dir></style></legend>

                <small id='mdsPY'></small><noframes id='mdsPY'>

                本文介绍了两个坐标之间的地理中点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

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

                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}
                

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

                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}

                这是我的代码:

                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;
                }
                

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

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

                谢谢

                推荐答案

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

                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;
                }
                

                这篇关于两个坐标之间的地理中点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)

                  <small id='aYsRm'></small><noframes id='aYsRm'>

                  <legend id='aYsRm'><style id='aYsRm'><dir id='aYsRm'><q id='aYsRm'></q></dir></style></legend>

                    <bdo id='aYsRm'></bdo><ul id='aYsRm'></ul>
                    • <tfoot id='aYsRm'></tfoot>
                        <tbody id='aYsRm'></tbody>
                      <i id='aYsRm'><tr id='aYsRm'><dt id='aYsRm'><q id='aYsRm'><span id='aYsRm'><b id='aYsRm'><form id='aYsRm'><ins id='aYsRm'></ins><ul id='aYsRm'></ul><sub id='aYsRm'></sub></form><legend id='aYsRm'></legend><bdo id='aYsRm'><pre id='aYsRm'><center id='aYsRm'></center></pre></bdo></b><th id='aYsRm'></th></span></q></dt></tr></i><div id='aYsRm'><tfoot id='aYsRm'></tfoot><dl id='aYsRm'><fieldset id='aYsRm'></fieldset></dl></div>