// 117.11726427,36.67414252 public static void MarsToEarth(double[] marsLong, double[] marsLat, double[] earthLong, double[] earthLat, double[] newMarsLong, double[] newMarsLat, out double[] newEarthLong, out double[] newEarthLat) { int ptNum = marsLong.Length; double[,] X = MatrixTool.Init(2 * ptNum, 1); double[,] Y = MatrixTool.Init(2 * ptNum, 1); int pN = newMarsLong.Length; double[] XX = new double[pN * 2]; double[] YY = new double[pN * 2]; newEarthLong = new double[pN]; newEarthLat = new double[pN]; //double[] YYRes = new double[pN * 2]; for (int i = 0; i < ptNum; i++) { CoordinateConverter.LatLonToUTMXY(marsLat[i], marsLong[i], out X[2 * i + 0, 0], out X[2 * i + 1, 0]); CoordinateConverter.LatLonToUTMXY(earthLat[i], earthLong[i], out Y[2 * i + 0, 0], out Y[2 * i + 1, 0]); CoordinateConverter.LatLonToUTMXY(newMarsLat[i], newMarsLong[i], out XX[2 * i + 0], out XX[2 * i + 1]); } CoordTrans4Param ct = new CoordTrans4Param(); ct.CalculateTrans4Param(X, Y); for (int i = 0; i < pN; i++) { ct.TransCoord(XX[i * 2 + 0], XX[i * 2 + 1], out YY[i * 2 + 0], out YY[i * 2 + 1]); CoordinateConverter.UTMXYToLatLon(YY[i * 2 + 0], YY[i * 2 + 1], out newEarthLat[i], out newEarthLong[i]); //Console.WriteLine("准确的 x {0}, y {1}, 计算的 x {2} , y {3} ", YYRead[i * 2 + 0], YYRead[i * 2 + 1], YY84[i * 2 + 0], YY84[i * 2 + 1]); //Console.WriteLine("准确的 x {0}, y {1}, 计算的 x {2} , y {3} ", YYRead[i * 2 + 0], YYRead[i * 2 + 1], YY[i * 2 + 0] / sx + cx2, YY[i * 2 + 1] / sy + cy2); } //return YYRes; }
private void button2_Click1(object sender, EventArgs e) { double x1, y1, x2, y2; x1 = 119; x2 = 120; y1 = y2 = 35; Console.WriteLine("x:" + CoordinateConverter.getUTMDistance(x1, y1, x2, y2)); Console.WriteLine("y:" + CoordinateConverter.getUTMDistance(x1, y1, x1, y2 + 1)); string fileName = @"D:\sevenParamsTest.xlsx"; //if (chainList.Count > 0) // chainList.Clear(); //LoadDataTableFromExcel(fileName, "Sheet1"); int ptNum = 5; double[,] X = MatrixTool.Init(2 * ptNum, 1); double[,] Y = MatrixTool.Init(2 * ptNum, 1); int pN = 10; double[] XX = new double[pN * 2]; double[] YYRead = new double[pN * 2]; double[] YY = new double[pN * 2]; int i = 0; int j = 0; int k = 0; foreach (DataRow dr in ds.Tables["Sheet1"].Rows) { if (i % 40 == 0 && j < ptNum) { X[j * 2 + 0, 0] = Convert.ToDouble(dr["North"]); X[j * 2 + 1, 0] = Convert.ToDouble(dr["East"]); Y[j * 2 + 0, 0] = Convert.ToDouble(dr["Longitude"]); Y[j * 2 + 1, 0] = Convert.ToDouble(dr["Latitude"]); j++; } if (i % 20 == 10 && k < pN) { XX[k * 2 + 0] = Convert.ToDouble(dr["North"]); XX[k * 2 + 1] = Convert.ToDouble(dr["East"]); YYRead[k * 2 + 0] = Convert.ToDouble(dr["Longitude"]); YYRead[k * 2 + 1] = Convert.ToDouble(dr["Latitude"]); k++; } i++; if (j == ptNum && k == pN) { break; } } double cx1, cy1, cx2, cy2; cx1 = cy1 = cx2 = cy2 = 0; double sx = 91310; double sy = 111000; for (i = 0; i < pN; i++) { cx1 += XX[2 * i]; cy1 += XX[2 * i + 1]; cx2 += YYRead[2 * i]; cy2 += YYRead[2 * i + 1]; } cx1 /= pN; cy1 /= pN; cx2 /= pN; cy2 /= pN; for (i = 0; i < ptNum; i++) { X[2 * i, 0] = X[2 * i, 0] - cx1; X[2 * i + 1, 0] = X[2 * i + 1, 0] - cy1; Y[2 * i, 0] = (Y[2 * i, 0] - cx2) * sx; Y[2 * i + 1, 0] = (Y[2 * i + 1, 0] - cy2) * sy; } for (i = 0; i < pN; i++) { XX[2 * i] = XX[2 * i] - cx1; XX[2 * i + 1] = XX[2 * i + 1] - cy1; } CoordTrans4Param ct = new CoordTrans4Param(); ct.CalculateTrans4Param(X, Y); for (i = 0; i < pN; i++) { ct.TransCoord(XX[i * 2 + 0], XX[i * 2 + 1], out YY[i * 2 + 0], out YY[i * 2 + 1]); Console.WriteLine("准确的 x {0}, y {1}, 计算的 x {2} , y {3} ", YYRead[i * 2 + 0], YYRead[i * 2 + 1], YY[i * 2 + 0] / sx + cx2, YY[i * 2 + 1] / sy + cy2); } }