/// <summary> /// 计算两个点之间归一化的距离 /// </summary> /// <param name="pt1">起点</param> /// <param name="pt2">终点</param> /// <returns>两个点归一化的距离</returns> public static double P2PdistanceCompute2one(PointInfo pt1, PointInfo pt2) { double s = -1; double x1 = pt1.x2one, y1 = pt1.y2one, x2 = pt2.x2one, y2 = pt2.y2one; double dx = x1 - x2, dy = y1 - y2; s = Math.Sqrt(dx * dx + dy * dy); return(s); }
/// <summary> /// 计算某点到随机点集的距离数组(归一化后的),与F函数相关 /// </summary> /// <param name="pt">输入点</param> /// <param name="randPointList">随机点集</param> /// <returns>输入点与随机点集的距离数组</returns> public static double[] P2RandPtDistanceArr(ref PointInfo pt, List <PointInfo> randPointList) { double[] distanceToRandPonintsArr = new double[randPointList.Count]; for (int i = 0; i < randPointList.Count; i++) { double s = P2PdistanceCompute2one(pt, randPointList[i]); distanceToRandPonintsArr[i] = s; } pt.distanceToRandPonintsArr = distanceToRandPonintsArr; return(distanceToRandPonintsArr); }
public double[] GetMinDisToRandPtArr() { for (int i = 0; i < pointNum; i++) { PointInfo pt = pointInfoList[i]; Algorithm.P2RandPtDistanceArr(ref pt, randPtlist); minDisToRandPtArr[i] = Algorithm.MinDistanceToRandPt(ref pt, randPtlist); pointInfoList[i].nearestDistanceToRandPonints = pt.nearestDistanceToRandPonints; pointInfoList[i].nearestPointInRandPonints = pt.nearestPointInRandPonints; } return(minDisToRandPtArr); }
/// <summary> /// 从一条犯罪数据中计算出其高斯平面坐标 /// </summary> /// <returns>空间的二维点</returns> public PointInfo ParseXY() { PointInfo pt = new PointInfo(); SpacePoint spt = new SpacePoint(); spt.B = CoorTran.Algorithm.D2R(latitude); spt.L = CoorTran.Algorithm.D2R(longitude); CoorTran.Algorithm.BL2xy(new EarthPara(), spt); pt.x = spt.x; pt.y = spt.y; pt.pointID = incident_id; return(pt); }
/// <summary> /// 生成随机点集x、y均在0-1之间 /// </summary> /// <param name="size">随机点集的大小</param> /// <returns>随机点集的列表</returns> public static List <PointInfo> GenerateRandPointList(int size) { List <PointInfo> randPointList = new List <PointInfo>(); for (int i = 0; i < size; i++) { Random ra = new Random(); PointInfo pt = new PointInfo(); pt.x2one = ra.NextDouble(); pt.y2one = ra.NextDouble(); randPointList.Add(pt); } return(randPointList); }
/// <summary> /// 计算某点到随机点集的最邻近距离(归一化后的),与F函数相关 /// </summary> /// <param name="pt">输入点</param> /// <param name="randPointList">随机点集</param> /// <returns>输入点与随机点集的最邻近距离</returns> public static double MinDistanceToRandPt(ref PointInfo pt, List <PointInfo> randPointList) { double minDis = -1; List <double> minDisList; //判断是否已经求得该点到随机点集的距离矩阵 if (pt.distanceToRandPonintsArr.Count() > 0) { minDisList = pt.distanceToRandPonintsArr.ToList(); } else { minDisList = P2RandPtDistanceArr(ref pt, randPointList).ToList(); } minDis = minDisList.Min(); int minIndex = minDisList.IndexOf(minDis); pt.nearestDistanceToRandPonints = minDis; pt.nearestPointInRandPonints = randPointList[minIndex]; return(minDis); }