/// <summary> /// convert geodetic to cartesian (ECEF) coordinates /// 输入: geodetic lat(deg N), lon(deg E), //// height above ellipsoid (meters) /// 输出: X,Y,Z in meters in cartesian (ECEF) coordinates /// </summary> public void GeodeticToCartesian(double lat, double lon, double height, out double X, out double Y, out double Z) //大地坐标转化为笛卡尔坐标 { double N = ell.N(lat); //计算卯酉圈曲率半径 double slat = Math.Sin(lat); double clat = Math.Cos(lat); X = (N + height) * clat * Math.Cos(lon);//具体的转化为XYZ的公式 Y = (N + height) * clat * Math.Sin(lon); Z = (N * (1 - ell.eccSq) + height) * slat; }
/// <summary> /// convert geodetic to cartesian (ECEF) coordinates /// 输入: geodetic lat(deg N), lon(deg E), //// height above ellipsoid (meters) /// 输出: X,Y,Z in meters in cartesian (ECEF) coordinates /// </summary> public void GeodeticToCartesian(double lat, double lon, double height, out double X, out double Y, out double Z)//GeodeticToCartesian大地to笛卡尔 //BLH to XYZ { double N = ell.N(lat); double slat = Math.Sin(lat);//lat是纬度 latitude double clat = Math.Cos(lat); X = (N + height) * clat * Math.Cos(lon); //lon是经度 longitude Y = (N + height) * clat * Math.Sin(lon); Z = (N * (1 - ell.eccSq) + height) * slat; //eccentricity偏心率 }
/////<summary> ///// BL --> xy ///// 转换B,L 到x,y(高斯平面坐标系) ///// </summary> ///// <param name="B"> 纬度(以弧度单位)</param> ///// <param name="L"> 经度(以弧度为单位),</param> ///// <param name="x">x方向坐标(以m为单位)</param> ///// <param name="y">y方向坐标(以m为单位)</param> //public void GeodeticToGrid(double B, double L, out double x, out double y) //{ // double N = ell.N(B); //A / Math.Sqrt(1.0 - eccSq * slat * slat); // double X = MeridianArclength(B); // L = (L - L0); // double slat = Math.Sin(B); // double m = L * Math.Cos(B); // double m2 = m * m; // double m3 = m2 * m; // double m4 = m3 * m; // double m5 = m4 * m; // double m6 = m5 * m; // double t = Math.Tan(B); // double t2 = t * t; // double t4 = t2 * t2; // double eta = Math.Sqrt(ell.eccSq / (1 - ell.eccSq)) * Math.Cos(B); // double eta2 = eta * eta; // double eta4 = eta2 * eta2; // x = X + N * t * (0.5 * m2 + 1 / 24 * (5 - t2 + 9 * eta2 + 4 * eta4) * m4 // + 1 / 720 * (61 - 58 * t2 + t4) * m6); // y = N * (m + 1 / 6 * (1 - t2 + eta2) * m3 + // 1 / 120 * (5 - 18 * t2 + t4 + 14 * eta2 - 58 * eta2 * t2) * m5); // y = y + Y0; //} ///// <summary> ///// xy -->BL ///// 高斯平面坐标转换为大地坐标 ///// </summary> ///// <param name="x">x坐标(以m为单位)</param> ///// <param name="y">y坐标(以m为单位)</param> ///// <param name="lat">纬度(以°为单位)</param> ///// <param name="lon">经度(以°为单位)</param> //public void GridToGeodetic(double x, double y, out double lat, out double lon) //{ // //底点维度 EndPointLat(x,eccSq,B); // double B_f = EndPointLat(x); // double slat = Math.Sin(B_f); // double clat = Math.Cos(B_f); // double N = ell.a / Math.Sqrt(1.0 - ell.eccSq * slat * slat); // double t = Math.Tan(B_f); // double t2 = t * t; // double t4 = t2 * t2; // double etaSq = ell.eccSq / (1 - ell.eccSq) * clat * clat; // double Y1 = (y - Y0) / N; // double Y2 = Y1 * Y1; // double Y3 = Y2 * Y1; // double Y4 = Y3 * Y1; // double Y5 = Y4 * Y1; // double Y6 = Y5 * Y1; // double V = 1 + etaSq; // lat = B_f - 0.5 * t * V * Y2 + 1 / 24 * (5 + 3 * t2 + etaSq - // 9 * etaSq * t2) * V * t * Y4 - 1 / 720 * (61 + 90 * t2 + 45 * t4) * V * t * Y6; // lon = 1 / clat * (Y1 - 1 / 6 * (1 + 2 * t2 + etaSq) * Y3 + // 1 / 120 * (5 + 28 * t2 + 24 * t4 + 6 * etaSq + 8 * etaSq * t2) * Y5); // lon += L0; //} /// <summary> /// 计算系数 /// </summary> /// <param name="X">弧度长</param> /// <param name="B">纬度</param> /// <param name="aCoef">系数</param> private void CoeffA(double X, double B, double[] aCoef) { double a0, a1, a2, a3, a4, a5, a6; double N, t, eta; N = ell.N(B); t = ell.Tan(B); eta = ell.Eta(B); a0 = X; a1 = N * Math.Cos(B); a2 = N * t * Math.Pow(Math.Cos(B), 2) / 2.0; a3 = N * (1 - t * t + eta * eta) * Math.Pow(Math.Cos(B), 3) / 6.0; a4 = N * t * (5 - t * t + 9 * eta * eta + 4 * Math.Pow(eta, 4)) * Math.Pow(Math.Cos(B), 4) / 24.0; a5 = N * (5 - 18 * t * t + Math.Pow(t, 4) + 14 * eta * eta - 58 * Math.Pow(eta, 2) * Math.Pow(t, 2)) * Math.Pow(Math.Cos(B), 5) / 120.0; a6 = N * t * (61 - 58 * t * t + Math.Pow(t, 4) + 270 * eta * eta - 330 * Math.Pow(eta, 2) * Math.Pow(t, 2)) * Math.Pow(Math.Cos(B), 6) / 720.0; aCoef[0] = a0; aCoef[1] = a1; aCoef[2] = a2; aCoef[3] = a3; aCoef[4] = a4; aCoef[5] = a5; aCoef[6] = a6; }