public void TestFourPara2() { double x1 = 475000; double y1 = 3754000; double dx1 = 500; double dy1 = 300; double r1 = 10d / 3600d * 4d * Math.Atan(1d); double s1 = 5d; FourPara four1 = new FourPara { Mode = enumFourMode.RSO, DX = dx1, DY = dy1, R = r1, S = s1 }; FourPara four2 = FourPara.ChangeMode(four1, enumFourMode.ORS); FourPara four3 = FourPara.GetInv(four1); FourPara four4 = FourPara.GetInv(four2); double x11 = 0d, y11 = 0d, x22 = 0d, y22 = 0d, x33 = 0d, y33 = 0d, x44 = 0d, y44 = 0d; FourTrans(four1, x1, y1, ref x11, ref y11); FourTrans(four2, x1, y1, ref x22, ref y22); FourTrans(four3, x11, y11, ref x33, ref y33); FourTrans(four4, x22, y22, ref x44, ref y44); Assert.IsTrue(Math.Abs(x11 - x22) < 1e-5, "正向:两个模型X方向转换结果不一致"); Assert.IsTrue(Math.Abs(y11 - y22) < 1e-5, "正向:两个模型Y方向转换结果不一致"); Assert.IsTrue(Math.Abs(x33 - x44) < 1e-5, "反向:两个模型Y方向转换结果不一致"); Assert.IsTrue(Math.Abs(y33 - y44) < 1e-5, "反向:两个模型Y方向转换结果不一致"); }
public void TestFourPara3() { string path = @"C: \Users\niuni\Desktop\common802000.txt"; List <string[]> lines = FileHelper.ReadThenSplitLine(path, ' '); List <double> x1 = new List <double>(); List <double> y1 = new List <double>(); List <double> x2 = new List <double>(); List <double> y2 = new List <double>(); for (int i = 0; i < lines.Count; i++) { if (lines[i] == null || lines[i].Length < 5) { continue; } x1.Add(double.Parse(lines[i][1])); y1.Add(double.Parse(lines[i][2])); x2.Add(double.Parse(lines[i][3])); y2.Add(double.Parse(lines[i][4])); } FourPara four = FourPara.CalParaIter(x1, y1, x2, y2); }
private void FourTrans(FourPara four, double inX, double inY, ref double outX, ref double outY) { if (four is null) { return; } if (four.Mode == enumFourMode.ORS || four.Mode == enumFourMode.OSR) { outX = (1 + four.S * 1e-6) * (Math.Cos(four.R) * (inX + four.DX) + Math.Sin(four.R) * (inY + four.DY)); outY = (1 + four.S * 1e-6) * (-Math.Sin(four.R) * (inX + four.DX) + Math.Cos(four.R) * (inY + four.DY)); } else { outX = (1 + four.S * 1e-6) * (Math.Cos(four.R) * inX + Math.Sin(four.R) * inY); outY = (1 + four.S * 1e-6) * (-Math.Sin(four.R) * inX + Math.Cos(four.R) * inY); outX += four.DX; outY += four.DY; } }
public void FourCal() { double dx, dy, r, s = 0; Random rand = new Random(); for (int i = 0; i < 10; i++) { dx = rand.Next(1, 200) + rand.NextDouble(); dy = rand.Next(50, 500) + rand.NextDouble(); r = (rand.Next(0, 10) + rand.NextDouble()) / 3600d * Angle.D2R; s = rand.Next(0, 10) + rand.NextDouble(); List <double> x1 = new List <double>(); List <double> x2 = new List <double>(); List <double> y1 = new List <double>(); List <double> y2 = new List <double>(); double xx1, yy1, xx2, yy2; for (int j = 0; j < 4; j++) { xx1 = rand.Next(-300000, 300000) + rand.NextDouble(); yy1 = rand.Next(-3000000, 3000000) + rand.NextDouble(); xx2 = (1 + s * 1e-6) * (Math.Cos(r) * xx1 + Math.Sin(r) * yy1) + dx; yy2 = (1 + s * 1e-6) * (-Math.Sin(r) * xx1 + Math.Cos(r) * yy1) + dy; x1.Add(xx1); y1.Add(yy1); x2.Add(xx2); y2.Add(yy2); } FourPara four = FourPara.CalPara(x1, y1, x2, y2); Assert.IsTrue(Math.Abs(four.DX - dx) < 1e-5); Assert.IsTrue(Math.Abs(four.DY - dy) < 1e-5); Assert.IsTrue(Math.Abs(four.R - r) < 1e-5); Assert.IsTrue(Math.Abs(four.S - s) < 1e-9, string.Format("{0} {1}", s, four.S)); } }
private void btnCal_Click(object sender, EventArgs e) { try { List <BLHCoordinate> pSourceBLH = new List <BLHCoordinate>(); List <XYZCoordinate> pSource = new List <XYZCoordinate>(); List <XYZCoordinate> pTo = new List <XYZCoordinate>(); List <XYZCoordinate> pToNew = new List <XYZCoordinate>(); if (txtB1.Text != "" && txtL1.Text != "") { pSourceBLH.Add(new BLHCoordinate(double.Parse(txtB1.Text), double.Parse(txtL1.Text), 0)); } if (txtB2.Text != "" && txtL2.Text != "") { pSourceBLH.Add(new BLHCoordinate(double.Parse(txtB2.Text), double.Parse(txtL2.Text), 0)); } if (txtB3.Text != "" && txtL3.Text != "") { pSourceBLH.Add(new BLHCoordinate(double.Parse(txtB3.Text), double.Parse(txtL3.Text), 0)); } if (txtB4.Text != "" && txtL4.Text != "") { pSourceBLH.Add(new BLHCoordinate(double.Parse(txtB4.Text), double.Parse(txtL4.Text), 0)); } if (txtB5.Text != "" && txtL5.Text != "") { pSourceBLH.Add(new BLHCoordinate(double.Parse(txtB5.Text), double.Parse(txtL5.Text), 0)); } if (txtB6.Text != "" && txtL6.Text != "") { pSourceBLH.Add(new BLHCoordinate(double.Parse(txtB6.Text), double.Parse(txtL6.Text), 0)); } if (txtX1.Text != "" && txtY1.Text != "") { pTo.Add(new XYZCoordinate(double.Parse(txtX1.Text), double.Parse(txtY1.Text), 0)); } if (txtX2.Text != "" && txtY2.Text != "") { pTo.Add(new XYZCoordinate(double.Parse(txtX2.Text), double.Parse(txtY2.Text), 0)); } if (txtX3.Text != "" && txtY3.Text != "") { pTo.Add(new XYZCoordinate(double.Parse(txtX3.Text), double.Parse(txtY3.Text), 0)); } if (txtX4.Text != "" && txtY4.Text != "") { pTo.Add(new XYZCoordinate(double.Parse(txtX4.Text), double.Parse(txtY4.Text), 0)); } if (txtX5.Text != "" && txtY5.Text != "") { pTo.Add(new XYZCoordinate(double.Parse(txtX5.Text), double.Parse(txtY5.Text), 0)); } if (txtX6.Text != "" && txtY6.Text != "") { pTo.Add(new XYZCoordinate(double.Parse(txtX6.Text), double.Parse(txtY6.Text), 0)); } int ptNum = 0; if (txtPtNum.Text != "") { ptNum = int.Parse(txtPtNum.Text); } double Lon = 0; if (pSourceBLH.Count > 1) { Lon = (int)pSourceBLH[0].L; } else { MessageBox.Show("请输入控制点坐标!"); return; } for (int i = 0; i < ptNum; i++) { XYZCoordinate wgsxy = GaussProjection.GaussProjCal(pSourceBLH[i], WGS84Datum, Lon); pSource.Add(wgsxy); pToNew.Add(pTo[i]); } double rms; FourPara forPara = Para4.Calc4Para(pSource, pTo, out rms); txtLon.Text = Lon + ""; txtDeltaX.Text = forPara.deltaX + ""; txtDeltaY.Text = forPara.deltaY + ""; txtAx.Text = forPara.Ax + ""; txtS.Text = forPara.scale + ""; } catch { MessageBox.Show("错误,请检查!"); } }
public static void ConvertTest() { List <XYZCoordinate> pSource = new List <XYZCoordinate>(); List <XYZCoordinate> pTo = new List <XYZCoordinate>(); //FourPara forPara = new FourPara(-439902.865, -3266656.406, 0.0013362875487730103, 0.99999205271109981); StreamReader sr = new StreamReader(@"E:\Projects\张家口\张家口控制点-宣化.txt"); //StreamWriter sw = new StreamWriter(@"E:\Projects\杭州项目\点云数据\data-20120517-123249_1_left.xyzt"); string line; double b, l, h, x1 = 0, y1 = 0, x2 = 0, y2 = 0, weekSec; int i = 1; while ((line = sr.ReadLine()) != null) { string[] strs = line.Split(' '); //b = double.Parse(strs[0]) + double.Parse(strs[1]) / 60 + double.Parse(strs[2]) / 3600; //l = double.Parse(strs[3]) + double.Parse(strs[4]) / 60 + double.Parse(strs[5]) / 3600; x1 = double.Parse(strs[0]); y1 = double.Parse(strs[1]); x2 = double.Parse(strs[2]); y2 = double.Parse(strs[3]); //l = double.Parse(strs[4]) + double.Parse(strs[5]) / 60 + double.Parse(strs[6]) / 3600; //b = double.Parse(strs[7]) + double.Parse(strs[8]) / 60 + double.Parse(strs[9]) / 3600; //int intb = (int)b; //double millib = b - intb; //int minb = (int)(millib * 100); //double secb = (millib * 100 - minb) * 100; //b = intb + minb / 60.0 + secb / 3600; //int intl = (int)l; //double millil = l - intl; //int minl = (int)(millil * 100); //double secl = (millil * 100 - minl) * 100; //l = intl + minl / 60.0 + secl / 3600; //BLHCoordinate wgsblh = GaussProjection.GaussProjInvCal(new XYZCoordinate(x, y, h), CoordConsts.WGS84Datum, 105); //XYZCoordinate wgsxyh = GaussProjection.GaussProjCal(new BLHCoordinate(b,l,0), CoordConsts.WGS84Datum, 108); pSource.Add(new XYZCoordinate(y1, x1, 0)); pTo.Add(new XYZCoordinate(y2, x2, 0)); } sr.Close(); //sw.Close(); double rms; FourPara forPara = Para4.Calc4Para(pSource, pTo, out rms); //SevenPara bigPara7 = Para7.CalBigAngle7Paras(pSource,pTo); //SevenPara sevenPara = Para7.Calc7Para(pSource, pTo); //SevenPara sevenPara = new SevenPara(-3297.3976, 12883.8090, 17375.9167, 0.4908300492, 0.1026210199, 0.053060665555, -1286.6821354); //XYZCoordinate wgs84xyz = new XYZCoordinate(103.51925547390123, 30.588686329132248, 486.1406); //XYZCoordinate bj54xyz = Para7.Para7Convert(wgs84xyz, sevenPara); //XYZCoordinate wgsxyh = GaussProjection.GaussProjCal(new BLHCoordinate(30.5857555556, 103.5258305556, 16.580), CoordConsts.WGS84Datum, 105); //FourPara forPara = new FourPara(-439902.86518674204, -3266656.40625, 0.0013362875487730103, 0.99999205271109981); //XYZCoordinate localCor = Para4.Para4Convert(wgsxyh, forPara); }