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;

        }

    }

你可能感兴趣的:(Graph)