zoukankan      html  css  js  c++  java
  • 判断一个经纬度是不是在一个范围内

            /// <summary>
            /// 判断经纬度是否在范围类
            /// </summary>
            /// <param name="longitudeCur">经度</param>
            /// <param name="latitudeCur">纬度</param>
            /// <param name="pathList"></param>
            /// <returns></returns>
            public static bool IsInRegion(double longitudeCur, double latitudeCur, IList<RegionPath> pathList)
            {
                if (pathList.Count < 3)//点小于3无法构成多边形
                {
                    return false;
                }
                int iSum = 0;
                int pathCount = pathList.Count;
                double longStart = 0, latiStart = 0, longEnd = 0, latiEnd = 0;
                double dLong = 0;
                for (int i = 0; i < pathCount; i++)
                {
                    int nextIndex = i + 1;
                    if (i == pathCount - 1)
                    {
                        nextIndex = 0;
                    }
                    longStart = pathList[i].Longitude;
                    latiStart = pathList[i].Latitude;
                    longEnd = pathList[nextIndex].Longitude;
                    latiEnd = pathList[nextIndex].Latitude;
    
                    //判断纬度即Y坐标是否在2点的Y坐标内,只有在其内水平线才会相交
                    if ((latitudeCur >= latiStart && latitudeCur < latiEnd) || 
                        (latitudeCur >= latiEnd && latitudeCur < latiStart)) 
                    {
                        if (Math.Abs(latiStart-latiEnd)>0)
                        {
                            dLong = longStart - ((longStart - longEnd) * (latiStart - latitudeCur)) / (latiStart - latiEnd);
                            if (dLong < longitudeCur)
                            {
                                iSum++;
                            }
                        }
                    }
                }
    
                if ((iSum % 2) != 0)
                {
                    return true;
                }
                return false;
            }
  • 相关阅读:
    13自下而上语法分析
    12 递归下降语法分析
    LL(1)文法的判断,递归下降分析程序
    消除左递归
    作业4 .K均值算法--应用
    作业3 K均值算法
    作业2 机器学习相关数学基础
    作业1 机器学习概述
    作业15 语法制导的语义翻译
    作业14:算符优先分析
  • 原文地址:https://www.cnblogs.com/tangchun/p/9467985.html
Copyright © 2011-2022 走看看