# 三维场景计算任意两点的空间距离

### 方法一 用测地线的接口来计算两个三维点的空间距离

                Point2D point1 = new Point2D();
point1.X = point3ds[0].X;
point1.Y = point3ds[0].Y;
Point2D point2 = new Point2D();
point2.X = point3ds[1].X;
point2.Y = point3ds[1].Y;
double S_Distance = Geometrist.ComputeGeodesicDistance(point2ds, 6378137, 0.00335281066474748);


                double K_Distance =Math.Pow((S_Distance * S_Distance + H * H),0.5);


### 方法二 通过投影转换来计算两个三维点的空间距离

                PrjCoordSys prjcoordsys = new PrjCoordSys();
double S_Longitude = (point3ds[1].X + point3ds[0].X) / 2;
int D = (int)((S_Longitude + 6) / 6);
int centralmeridian = D * 6 - 3;

GeoCoordSys geocoordsys = new GeoCoordSys();
geocoordsys.Type = GeoCoordSysType.Wgs1984;
prjcoordsys.GeoCoordSys = geocoordsys;

Projection projection = new Projection();
projection.Type = ProjectionType.TransverseMercator;
prjcoordsys.Projection = projection;

PrjParameter prjparameter = new PrjParameter();
prjparameter.CentralMeridian = centralmeridian;
prjparameter.FalseEasting = 500000;
prjparameter.ScaleFactor = 0.9996;
prjcoordsys.PrjParameter = prjparameter;


                PrjCoordSys prjcoordsys = this.GetPrjCoordSys();
bool a = CoordSysTranslator.Forward(point2ds,prjcoordsys);

GeoPoint geopoint1=new GeoPoint(point2ds[0]);
GeoPoint geopoint2=new GeoPoint(point2ds[1]);

double S_Distance = Geometrist.Distance(geopoint1,geopoint2);


                double K_Distance = Math.Pow((S_Distance * S_Distance + H * H), 0.5);


### 范例效果展示图

• 本文已收录于以下专栏：

举报原因： 您举报文章：三维场景计算任意两点的空间距离 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)