馨馨 发表于 2016-5-6 22:27
有没有人啊,求指点
用离网格点最近的几个点进行计算
下面是c++的 用距离加权平均法计算网格点的属性值的代码
- // 用距离加权平均法计算网格点的属性值
- AcGePoint3dArray CCFGWDLG::CalculateValueByJL(const AcGePoint3dArray &gridPts, const AcGePoint3dArray &gcdPts)
- {
- AcGePoint3dArray newgridPts;
- int kk = gcdPts.length();
- if (kk >= 10)
- {
- kk = 10;
- }
- for (int i = 0; i < gridPts.length(); i++)
- {
- AcGePoint2dArray distanceArray;
- AcGePoint3d pt1 = gridPts;
- for (int j = 0; j < gcdPts.length(); j++)
- {
- AcGePoint3d pt2 = gcdPts[j];
- double dist = GetDistance(pt1.x, pt1.y, pt2.x, pt2.y);
- AcGePoint2d temp((double)j, dist);
- distanceArray.append(temp);
- }
- SortPointsOnY(distanceArray, 0, distanceArray.length() - 1);
- double up = 0, down = 0, dz;
- for (int k = 0; k < kk; k++)
- {
- AcGePoint2d temp = distanceArray[k];
- int index = (int)temp.x;
- double ptz = gcdPts[index].z;
- double dis = distanceArray[index].y;
- up += ptz / dis;
- down += 1 / dis;
- }
- dz = up / down;
- AcGePoint3d pt3d(pt1.x, pt1.y, dz);
- newgridPts.append(pt3d);
- }
- return newgridPts;
- }
|