zoukankan      html  css  js  c++  java
  • calculate the distance of 2 [geographic coordinates]

        class PublicFun

        {

        }

        /// <summary>

        /// calculate the distance

        /// </summary>

        public struct EarthPoint

        {

            //equatorial radius:  WGS84 standard major semi-axis of the earth(unit:m)  

            public const double Ea = 6378137; 

            public const double Eb = 6356725; // 极半径   

            public readonly double Longitude, Latidute;

            public readonly double Jd;

            public readonly double Wd;

            public readonly double Ec;

            public readonly double Ed;

            public EarthPoint(double _Longitude, double _Latidute)

            {

                Longitude = _Longitude;

                Latidute = _Latidute;

                Jd = Longitude * Math.PI / 180; //convert to angle

                Wd = Latidute * Math.PI / 180; //convert to angle

                Ec = Eb + (Ea - Eb) * (90 - Latidute) / 90;

                Ed = Ec * Math.Cos(Wd);

            }

            /// <summary>

            ///  return distance of two point(unit:km)

            /// </summary>

            /// <param name="_Point"></param>

            /// <returns></returns>

            public double Distance(EarthPoint _Point)

            {

                double dx = (_Point.Jd - Jd) * Ed;

                double dy = (_Point.Wd - Wd) * Ec;

                return Math.Sqrt(dx * dx + dy * dy)/1000;

            }

        }

  • 相关阅读:
    167. 两数之和 II
    14. 最长公共前缀
    28. 实现strStr()
    118. 杨辉三角
    54. 螺旋矩阵
    498. 对角线遍历
    66. 加一
    747. 至少是其他数字两倍的最大数
    34. 在排序数组中查找元素的第一个和最后一个位置
    164. 寻找峰值
  • 原文地址:https://www.cnblogs.com/scottgu/p/2220425.html
Copyright © 2011-2022 走看看