利用C#编写一个附和闭合导线平差程序
文章目錄
- 一、前言
- 二、代碼界面展示
- 三、代碼運算結果展示
- 3.1 閉合導線
- 3.1.1 通過txt文件導入原始數據
- 3.1.2 設置
- 3.1.3 計算
- 3.1.4 繪圖
- 3.1.5 數據導出
- 3.1.6 整體展示
- 3. 2 附和導線
- 四、源代碼
- 五、結語
一、前言
本程序是使用C# 編寫的一個附和閉合導線平差程序
閉合導線:兩個已知點,一個已知點+方位角;
附和導線:雙定向附和導線;
前面都不是重點,有需要的直接看代碼
二、代碼界面展示
Form1(大窗體)中控件有:Menu,tabControl,dataGridView。
Form2(小窗體)中控件有:radioButton,comboBox,label,textbox button。
三、代碼運算結果展示
3.1 閉合導線
3.1.1 通過txt文件導入原始數據
沒有的數據我用的0代替,沿用的水準測量程序的讀取代碼。
我這里的數據是直接給出了水平角了。
有些同學實習給的原始數據是盤左盤右數據。如果想要程序計算,需要多設置個幾變量,如果想要數據顯示出來的話,表格,數據導入那里也需要修改一下,但是運算邏輯是沒有變的,自己改一下應該不難。
實在不會的話,建議自己手動先把水平角算出來,再使用程序計算。
數據一:(2個已知點-右角)
數據二:(2個已知點-左角)
數據三:(方位角(48.4319)-右角)
數據四:(方位角(100)-右角)
3.1.2 設置
數據一:(2個已知點-右角)
數據二:(2個已知點-左角)
數據三:(方位角(48.4319)-右角)
數據四:(方位角(100)-右角)
3.1.3 計算
數據一:(2個已知點-右角)
計算結果和工程測量大師的是差不多的,mm位上有一些數據有差別,應該主要是我整個計算的過程中都沒有去避免double的精度誤差(不明白精度誤差的可以去搜搜看看)。如果你要參考我的代碼可以自己添加使用round來保留位數。
這個界面上面是datagridview,下面是richtextbox,表格設計成這樣其實不符合導線平差計算表的樣式的。主要是自己沒去學習表格的設計,能力不足,所以按照工程測量大師的表格設計的表。限差這些我隨便找的一個標準。但是這個數據本身計算出來就是不合格的。
數據二:(2個已知點-左角)
與他自己計算的數據可以進行對比
數據差別的來源
1.角度改正數的分配,我程序分配的邏輯是先均分,多出來的分配給邊長較長的。
2.位數保留,和數據一 一樣
不過最后計算的B點坐標,程序和原始數據一樣。
數據三:(方位角(48.4319)-右角)
數據四:(方位角(100)-右角)
3.1.4 繪圖
這個功能只能大概畫出一個圖形,電腦畫圖的坐標系和測量坐標系不一樣,所以需要轉換。程序畫的時候已經轉換了
說明一下,這個程序能畫的坐標范圍為x∈[-224,224],y∈[-496,496],如果坐標不屬于這里面的就畫不出來。坐標太大的話需要你自己在繪圖那段代碼里面修改n,讓坐標同時縮小n倍。
但是如果你的坐標是(3465128.993,552965.750)這種的,x坐標和y坐標位數不一樣,設置n就沒有用了,就畫不出來了。
當然你可以自己發力,畫出圖形來。
數據一:(2個已知點+右角)
n=5
數據二:(2個已知點-左角)
n=5
畫出來確實像一個廠房的結構
數據三:(方位角(48.4319)-右角)
n=5
數據四:(方位角(100)-右角)
n=5
3.1.5 數據導出
這個沒什么好聊的,就是把計算的數據導出成excel
數據一:(2個已知點+右角)
3.1.6 整體展示
3. 2 附和導線
這里我就不過多描述了,就是計算雙定向附和導線
實驗數據都是搜索的,經過了驗證的。
數據一
數據二
四、源代碼
namespace 附和閉合導線平差程序 {public partial class Form1 : Form{public Form1(){InitializeComponent();}//畫圖設置Graphics g;int midx, midy;List<Point> curvelist;Form2 form2 = new Form2();List<RowData> rdatas = new List<RowData>();List<ResultData> rtdatas = new List<ResultData>();ResultData rtdata = new ResultData();RowData rdata = new RowData();Tolerance tolerance = new Tolerance();double D = 0, M = 0, S = 0;double d1 = 0, m1 = 0, s1 = 0;double d2 = 0, m2 = 0;private void 文件ToolStripMenuItem1_Click(object sender, EventArgs e){tabControl1.SelectedTab = tabControl1.TabPages[0];dataGridView1.Rows.Clear();rdatas.Clear();string[] temp;OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";ofd.Title = "打開數據文件";if (ofd.ShowDialog(this) == DialogResult.OK){StreamReader sr = new StreamReader(ofd.FileName);while (!sr.EndOfStream){temp = sr.ReadLine().Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);RowData rdata = new RowData();rdata.DH = temp[0];rdata.DMS = Convert.ToDouble(temp[1]);rdata.L = Convert.ToDouble(temp[2]);rdata.X = Convert.ToDouble(temp[3]);rdata.Y = Convert.ToDouble(temp[4]);rdatas.Add(rdata);}sr.Close();GridBuild1();}else{MessageBox.Show("輸入失敗");}}public void GridBuild1(){for (int i = 0; i < rdatas.Count; i++){dataGridView1.Rows.Add();dataGridView1.Rows[i].Cells[0].Value = rdatas[i].DH;dataGridView1.Rows[i].Cells[1].Value = rdatas[i].DMS;dataGridView1.Rows[i].Cells[2].Value = rdatas[i].L;dataGridView1.Rows[i].Cells[3].Value = rdatas[i].X;dataGridView1.Rows[i].Cells[4].Value = rdatas[i].Y;}}private void 設置ToolStripMenuItem_Click(object sender, EventArgs e){form2.ShowDialog();}private void 計算ToolStripMenuItem_Click(object sender, EventArgs e){tabControl1.SelectedTab = tabControl1.TabPages[1];ClearData();ShowHAandVandCHA();ShowL();ShowCA();ShowΔxandΔy();ShowCΔxandCΔy();ShowXandY();ShowTolerance();Tolerance tolerance1 = new Tolerance();}public void ShowHAandVandCHA(){//閉合if (form2.radioButton1.Checked){int n = 0, i = 0;if (form2.comboBox1.Text == "兩個已知點"){n = rdatas.Count - 2;i = 2;}else if (form2.comboBox1.Text == "一個已知點+方位角"){n = rdatas.Count - 1;i = 1;}double sumli = 180 * (n - 2);while (i < rdatas.Count){D += ReturnDMS(rdatas[i].DMS).d;M += ReturnDMS(rdatas[i].DMS).m;S += ReturnDMS(rdatas[i].DMS).s;i++;}tolerance.fβ = (D + M / 60.0 + S / 3600.0 - sumli) * 3600;for (i = 0; i < rdatas.Count; i++){dataGridView2.Rows.Add();dataGridView2.Rows[i].Cells[0].Value = rtdatas[i].DH;if (i == 0){rtdatas[i].X = rdatas[i].X;rtdatas[i].Y = rdatas[i].Y;dataGridView2.Rows[i].Cells[10].Value = rtdatas[i].X;dataGridView2.Rows[i].Cells[11].Value = rtdatas[i].Y;}else if (i == 1 && form2.comboBox1.Text == "兩個已知點"){rtdatas[i].X = rdatas[i].X;rtdatas[i].Y = rdatas[i].Y;dataGridView2.Rows[i].Cells[10].Value = rtdatas[i].X;dataGridView2.Rows[i].Cells[11].Value = rtdatas[i].Y;d1 = ReturnDMS(rdatas[i].DMS).d;m1 = ReturnDMS(rdatas[i].DMS).m;s1 = ReturnDMS(rdatas[i].DMS).s;double HAb = toDu(d1, m1, s1);rtdatas[i].HA = HAb;dataGridView2.Rows[i].Cells[1].Value = d1.ToString() + " " + m1.ToString() + " " + s1.ToString();}else{d1 = ReturnDMS(rdatas[i].DMS).d;m1 = ReturnDMS(rdatas[i].DMS).m;s1 = ReturnDMS(rdatas[i].DMS).s;double HAx = toDu(d1, m1, s1);rtdatas[i].HA = HAx;double S = VDistribution(s1, i);d2 = d1;m2 = m1;if (S < 0){S += 60;m2 = m1 - 1;}else if (S >= 60){S -= 60;m2 = m1 + 1;}else if (m2 < 0){m2 += 60;d2 = d1 - 1;}else if (m2 >= 60){m2 -= 60;d2 = d1 + 1;}double CHAx = toDu(d2, m2, S);rtdatas[i].CHA = CHAx;dataGridView2.Rows[i].Cells[1].Value = d1.ToString() + " " + m1.ToString() + " " + s1.ToString();dataGridView2.Rows[i].Cells[2].Value = Math.Round(rtdatas[i].V, 0).ToString();dataGridView2.Rows[i].Cells[3].Value = d2.ToString() + " " + m2.ToString() + " " + Math.Round(S, 0).ToString();}}}//附和else if (form2.radioButton2.Checked){double Xa = rdatas[0].X;double Ya = rdatas[0].Y;double Xb = rdatas[1].X;double Yb = rdatas[1].Y;double Theta1 = Math.Atan(Math.Abs((Yb - Ya) / (Xb - Xa)));double radCA = JudgementQuadrant(Theta1, 1, 0);double CAa = radCA * 180 / Math.PI;rtdatas[0].CA = CAa;double Xc = rdatas[rtdatas.Count - 2].X;double Yc = rdatas[rtdatas.Count - 2].Y;double Xd = rdatas[rtdatas.Count - 1].X;double Yd = rdatas[rtdatas.Count - 1].Y;double Theta2 = Math.Atan(Math.Abs((Yd - Yc) / (Xd - Xc)));double radCc = JudgementQuadrant(Theta2, rtdatas.Count - 1, rtdatas.Count - 2);double CAc = radCc * 180 / Math.PI;rtdatas[rtdatas.Count - 2].CA = CAc;for (int i = 1; i < rtdatas.Count - 1; i++){D += ReturnDMS(rdatas[i].DMS).d;M += ReturnDMS(rdatas[i].DMS).m;S += ReturnDMS(rdatas[i].DMS).s;}if (form2.comboBox2.Text=="右角"){double βli = rtdatas[0].CA - rtdatas[rtdatas.Count - 2].CA + ((rtdatas.Count - 2) * 180);double βce = D + M / 60.0 + S / 3600.0;tolerance.fβ = βce - βli;}else if (form2.comboBox2.Text == "左角"){double βli = rtdatas[rtdatas.Count - 2].CA - rtdatas[0].CA+360 + ((rtdatas.Count - 2) * 180);double βce = D + M / 60.0 + S / 3600.0;tolerance.fβ = βce - βli; }while (tolerance.fβ > 360){tolerance.fβ -= 360;}while (tolerance.fβ < -360){tolerance.fβ += 360;}tolerance.fβ =Math.Round( tolerance.fβ * 3600,0);for (int i = 0; i < rdatas.Count; i++){dataGridView2.Rows.Add();dataGridView2.Rows[i].Cells[0].Value = rtdatas[i].DH;if (i == 0 || i == rdatas.Count - 1){rtdatas[i].X = rdatas[i].X;rtdatas[i].Y = rdatas[i].Y;dataGridView2.Rows[i].Cells[10].Value = rtdatas[i].X;dataGridView2.Rows[i].Cells[11].Value = rtdatas[i].Y;}else{if (i == 1 || i == rtdatas.Count - 2){rtdatas[i].X = rdatas[i].X;rtdatas[i].Y = rdatas[i].Y;dataGridView2.Rows[i].Cells[10].Value = rtdatas[i].X;dataGridView2.Rows[i].Cells[11].Value = rtdatas[i].Y;}d1 = ReturnDMS(rdatas[i].DMS).d;m1 = ReturnDMS(rdatas[i].DMS).m;s1 = ReturnDMS(rdatas[i].DMS).s;double HAx = toDu(d1, m1, s1);rtdatas[i].HA = HAx;double S = VDistribution(s1, i);d2 = d1;m2 = m1;if (S < 0){S += 60;m2 =m1- 1;}else if (S>=60){S -= 60;m2=m1+ 1;}else if (m2 < 0){m2 += 60;d2 =d1- 1;}else if (m2>=60){m2 -= 60;d2 =d1+ 1;}double CHAx = toDu(d2, m2, S);rtdatas[i].CHA = CHAx;dataGridView2.Rows[i].Cells[1].Value = d1.ToString() + " " + m1.ToString() + " " + s1.ToString();dataGridView2.Rows[i].Cells[2].Value = Math.Round(rtdatas[i].V, 0).ToString();dataGridView2.Rows[i].Cells[3].Value = d2.ToString() + " " + m2.ToString() + " " + Math.Round(S, 0).ToString();}}}}//點號和水平角和改正后的水平角public void ShowL(){if (form2.radioButton1.Checked){int n = 0;if (form2.comboBox1.Text == "兩個已知點"){n = rdatas.Count - 1;}else if (form2.comboBox1.Text == "一個已知點+方位角"){n = rdatas.Count;}for (int i = 1; i < n; i++){rtdatas[i].L = rdatas[i].L;tolerance.fl += rtdatas[i].L;dataGridView2.Rows[i].Cells[5].Value = rtdatas[i].L;}}else if (form2.radioButton2.Checked){for (int i = 1; i < rdatas.Count - 2; i++){rtdatas[i].L = rdatas[i].L;tolerance.fl += rtdatas[i].L;dataGridView2.Rows[i].Cells[5].Value = rtdatas[i].L;}}}//展示距離public void ShowCA(){//閉合if (form2.radioButton1.Checked){int n = 0;if (form2.comboBox1.Text == "兩個已知點"){n = rdatas.Count - 1;}else if (form2.comboBox1.Text == "一個已知點+方位角"){n = rdatas.Count;}//已知點坐標(X1,Y1),(X2,Y2)double CAa = 0;double CAb = 0;for (int i = 0; i < n; i++){if (i == 0 && form2.comboBox1.Text == "兩個已知點"){double X1 = rdatas[0].X;double Y1 = rdatas[0].Y;double X2 = rdatas[1].X;double Y2 = rdatas[1].Y;double Theta = Math.Atan(Math.Abs((Y2 - Y1) / (X2 - X1)));double radCA = JudgementQuadrant(Theta, 1, 0);CAa = radCA * 180 / Math.PI;rtdatas[i].CA = CAa;int[] dms = toDMS(rtdatas[i].CA);dataGridView2.Rows[0].Cells[4].Value = dms[0].ToString() + " " + dms[1].ToString() + " " + dms[2].ToString();}else if (i == 0 && form2.comboBox1.Text == "一個已知點+方位角"){CAa = Convert.ToDouble(form2.textBox1.Text) + Convert.ToDouble(form2.textBox2.Text) / 60 + Convert.ToDouble(form2.textBox3.Text) / 3600;rtdatas[i].CA = CAa;int[] dms = toDMS(rtdatas[i].CA);dataGridView2.Rows[0].Cells[4].Value = dms[0].ToString() + " " + dms[1].ToString() + " " + dms[2].ToString();}else if (i == 1 && form2.comboBox1.Text == "兩個已知點"){if (form2.comboBox2.Text == "右角"){CAb = CAa - rtdatas[i].HA + 180;}if (form2.comboBox2.Text == "左角"){CAb = CAa + rtdatas[i].HA + 180;}if (CAb > 360){CAb -= 360;}if (CAb<0){CAb += 360;}rtdatas[i].CA = CAb;int[] dms1 = toDMS(rtdatas[i].CA);dataGridView2.Rows[i].Cells[4].Value = dms1[0].ToString() + " " + dms1[1].ToString() + " " + dms1[2].ToString();}else if (i == 1 && form2.comboBox1.Text == "一個已知點+方位角"){CAb = Calculate_CA(CAa, i);rtdatas[i].CA = CAb;int[] dms1 = toDMS(rtdatas[i].CA);dataGridView2.Rows[i].Cells[4].Value = dms1[0].ToString() + " " + dms1[1].ToString() + " " + dms1[2].ToString();}else{CAb = Calculate_CA(CAb, i);rtdatas[i].CA = CAb;int[] dms1 = toDMS(rtdatas[i].CA);dataGridView2.Rows[i].Cells[4].Value = dms1[0].ToString() + " " + dms1[1].ToString() + " " + dms1[2].ToString();}}}//附和else if (form2.radioButton2.Checked){double CAx=0;int[] dms = toDMS(rtdatas[0].CA);dataGridView2.Rows[0].Cells[4].Value = dms[0].ToString() + " " + dms[1].ToString() + " " + dms[2].ToString();int[] dms1= toDMS(rtdatas[rtdatas.Count-2].CA);dataGridView2.Rows[rtdatas.Count - 2].Cells[4].Value = dms1[0].ToString() + " " + dms1[1].ToString() + " " + dms1[2].ToString();for (int i = 1; i < rtdatas.Count-1; i++){if (i==1){CAx = Calculate_CA(rtdatas[0].CA, i);rtdatas[i].CA = CAx;int[] dms2 = toDMS(rtdatas[i].CA);dataGridView2.Rows[i].Cells[4].Value = dms2[0].ToString() + " " + dms2[1].ToString() + " " + dms2[2].ToString();}else{CAx = Calculate_CA(CAx, i);rtdatas[i].CA = CAx;int[] dms2 = toDMS(rtdatas[i].CA);dataGridView2.Rows[i].Cells[4].Value = dms2[0].ToString() + " " + dms2[1].ToString() + " " + dms2[2].ToString();}}}}//計算展示坐標方位角//計算坐標方位角public double Calculate_CA(double CA, int i){double CA1 = 0;if (form2.comboBox2.Text == "右角"){CA1 =CA - rtdatas[i].CHA + 180;}if (form2.comboBox2.Text == "左角"){CA1 = CA + rtdatas[i].CHA + 180;}while (CA1 >= 360){CA1 -= 360;}while (CA1 <0){CA1 += 360;}return CA1;}public void ShowΔxandΔy(){if (form2.radioButton1.Checked){int i = 0;if (form2.comboBox1.Text == "兩個已知點"){i = 2;}else if (form2.comboBox1.Text == "一個已知點+方位角"){i = 1;}while (i < rdatas.Count){if (form2.comboBox1.Text == "兩個已知點"){rtdatas[i].Δx = Math.Cos(rtdatas[i - 1].CA * Math.PI / 180) * rtdatas[i - 1].L;rtdatas[i].Δy = Math.Sin(rtdatas[i - 1].CA * Math.PI / 180) * rtdatas[i - 1].L;}else if (form2.comboBox1.Text == "一個已知點+方位角"){rtdatas[i].Δx = Math.Cos(rtdatas[i - 1].CA * Math.PI / 180) * rtdatas[i].L;rtdatas[i].Δy = Math.Sin(rtdatas[i - 1].CA * Math.PI / 180) * rtdatas[i].L;}tolerance.fx += rtdatas[i].Δx;tolerance.fy += rtdatas[i].Δy;dataGridView2.Rows[i].Cells[6].Value = Math.Round(rtdatas[i].Δx, 4);dataGridView2.Rows[i].Cells[7].Value = Math.Round(rtdatas[i].Δy, 4);i++;}tolerance.fD = Math.Sqrt(tolerance.fx * tolerance.fx + tolerance.fy * tolerance.fy);tolerance.K = tolerance.fD / tolerance.fl;}else if (form2.radioButton2.Checked){double fxce=0, fyce=0,fxli=0,fyli=0;fxli = rdatas[rdatas.Count - 2].X - rdatas[1].X;fyli = rdatas[rdatas.Count - 2].Y - rdatas[1].Y;for (int i = 1; i < rdatas.Count-2; i++){rtdatas[i].Δx = Math.Cos(rtdatas[i].CA * Math.PI / 180) * rtdatas[i].L;rtdatas[i].Δy = Math.Sin(rtdatas[i].CA * Math.PI / 180) * rtdatas[i].L;fxce += rtdatas[i].Δx;fyce += rtdatas[i].Δy;dataGridView2.Rows[i].Cells[6].Value = Math.Round(rtdatas[i].Δx, 4);dataGridView2.Rows[i].Cells[7].Value = Math.Round(rtdatas[i].Δy, 4);}tolerance.fx = fxce - fxli;tolerance.fy = fyce - fyli;tolerance.fD = Math.Sqrt(tolerance.fx * tolerance.fx + tolerance.fy * tolerance.fy);tolerance.K = tolerance.fD / tolerance.fl;}}//計算展示Δx和Δy和fd,fl,fx,fx,Kpublic void ShowCΔxandCΔy(){if (form2.radioButton1.Checked){int i = 0;double temp = 0, temp1 = 0;if (form2.comboBox1.Text == "兩個已知點"){i = 2;}else if (form2.comboBox1.Text == "一個已知點+方位角"){i = 1;}while (i < rdatas.Count){if (form2.comboBox1.Text == "兩個已知點"){temp = tolerance.fx * rtdatas[i - 1].L / tolerance.fl;temp1 = tolerance.fy * rtdatas[i - 1].L / tolerance.fl;}else if (form2.comboBox1.Text == "一個已知點+方位角"){temp = tolerance.fx * rtdatas[i].L / tolerance.fl;temp1 = tolerance.fy * rtdatas[i].L / tolerance.fl;}rtdatas[i].CΔx = rtdatas[i].Δx - temp;rtdatas[i].CΔy = rtdatas[i].Δy - temp1;dataGridView2.Rows[i].Cells[8].Value = Math.Round(rtdatas[i].CΔx, 4);dataGridView2.Rows[i].Cells[9].Value = Math.Round(rtdatas[i].CΔy, 4);i++;}}else if (form2.radioButton2.Checked){for (int i = 1; i < rdatas.Count-2; i++){double temp = 0, temp1 = 0;temp = tolerance.fx * rtdatas[i].L / tolerance.fl;temp1 = tolerance.fy * rtdatas[i].L / tolerance.fl;rtdatas[i].CΔx = rtdatas[i].Δx - temp;rtdatas[i].CΔy = rtdatas[i].Δy - temp1;dataGridView2.Rows[i].Cells[8].Value = Math.Round(rtdatas[i].CΔx, 4);dataGridView2.Rows[i].Cells[9].Value = Math.Round(rtdatas[i].CΔy, 4);}}}//計算展示CΔ和CΔypublic void ShowXandY(){if (form2.radioButton1.Checked){int i = 0;if (form2.comboBox1.Text == "兩個已知點"){i = 2;}else if (form2.comboBox1.Text == "一個已知點+方位角"){i = 1;}while (i < rdatas.Count){rtdatas[i].X = rtdatas[i - 1].X + rtdatas[i].CΔx;rtdatas[i].Y = rtdatas[i - 1].Y + rtdatas[i].CΔy;dataGridView2.Rows[i].Cells[10].Value = Math.Round(rtdatas[i].X, 4);dataGridView2.Rows[i].Cells[11].Value = Math.Round(rtdatas[i].Y, 4);i++;}}else if (form2.radioButton2.Checked){for (int i = 2; i < rtdatas.Count-1; i++){rtdatas[i].X = rtdatas[i - 1].X + rtdatas[i-1].CΔx;rtdatas[i].Y = rtdatas[i - 1].Y + rtdatas[i-1].CΔy;dataGridView2.Rows[i].Cells[10].Value = Math.Round(rtdatas[i].X, 4);dataGridView2.Rows[i].Cells[11].Value = Math.Round(rtdatas[i].Y, 4);}}}//計算展示X和Ypublic void ShowTolerance(){if (form2.radioButton1.Checked){int n = 0;if (form2.comboBox1.Text == "兩個已知點"){n = rdatas.Count - 2;}else if (form2.comboBox1.Text == "一個已知點+方位角"){n = rdatas.Count - 1;}richTextBox1.AppendText(Environment.NewLine);if (Math.Abs( Math.Round(tolerance.fβ, 0))> Math.Round(24 * Math.Sqrt(n), 4)){richTextBox1.Text = "角度閉合差為 fβ=" + Math.Round(tolerance.fβ, 0).ToString() + "″" + " fβ允=±24√n=±" + Math.Round(24 * Math.Sqrt(n), 4) + " 角度閉合差超限"+"\n";}else if (Math.Abs(Math.Round(tolerance.fβ, 0)) < Math.Round(24 * Math.Sqrt(n), 4)){richTextBox1.Text = "角度閉合差為 fβ=" + Math.Round(tolerance.fβ, 0).ToString() + "″" + " fβ允=±24√n=±" + Math.Round(24 * Math.Sqrt(n), 4) + "\n";}richTextBox1.Text += "fx=" + Math.Round(tolerance.fx, 4).ToString() + "m" + " fy=" + Math.Round(tolerance.fy, 4).ToString() + "m" + " fl=" + Math.Round(tolerance.fl, 4).ToString() + "m" + "\n";richTextBox1.Text += "導線全長閉合差fD =" + Math.Round(tolerance.fD, 4) + "m" + "\n";richTextBox1.Text += "導線全長相對閉合差容許值=" + (1.0 / 2000) + "\n";if (tolerance.K > 1.0 / 2000){richTextBox1.Text += "導線全長相對閉合差K =" + Math.Round(tolerance.K, 4) + ">" + (1.0 / 2000) + " " + "結果超限" + "\n";}else if (tolerance.K < 1.0 / 2000){richTextBox1.Text += "導線全長相對閉合差K =" + Math.Round(tolerance.K, 4) + "<" + (1.0 / 2000) + " " + "結果不超限" + "\n";}}else if (form2.radioButton2.Checked){int n = rtdatas.Count - 2;richTextBox1.AppendText(Environment.NewLine);richTextBox1.Text = "角度閉合差為 fβ=" + Math.Round(tolerance.fβ, 0).ToString() + "″" + " fβ允=±24√n=±" + Math.Round(24 * Math.Sqrt(n), 4) + "\n";richTextBox1.Text += "fx=" + Math.Round(tolerance.fx, 4).ToString() + "m" + " fy=" + Math.Round(tolerance.fy, 4).ToString() + "m" + " fl=" + Math.Round(tolerance.fl, 4).ToString() + "m" + "\n";richTextBox1.Text += "導線全長閉合差fD =" + Math.Round(tolerance.fD, 4) + "m" + "\n";richTextBox1.Text += "導線全長相對閉合差容許值=" + (1.0 / 2000) + "\n";if (tolerance.K > 1.0 / 2000){richTextBox1.Text += "導線全長相對閉合差K =" + Math.Round(tolerance.K, 4) + ">" + (1.0 / 2000) + " " + "結果超限" + "\n";}else if (tolerance.K < 1.0 / 2000){richTextBox1.Text += "導線全長相對閉合差K =" + Math.Round(tolerance.K, 4) + "<" + (1.0 / 2000) + " " + "結果不超限" + "\n";}}}//展示限差public void ClearData(){dataGridView2.Rows.Clear();rtdatas.Clear();D = 0; M = 0; S = 0;d1 = 0; m1 = 0; s1 = 0;tolerance.fx = 0;tolerance.fy = 0;tolerance.fl = 0;for (int i = 0; i < rdatas.Count; i++){ResultData rtdata = new ResultData();rtdata.DH = rdatas[i].DH;rtdatas.Add(rtdata);}}//計算前清理數據,避免數據重復計算public (double d, double m, double s) ReturnDMS(double DMS){double d, m, s;d = Math.Floor(DMS);m = Math.Floor(Math.Round(((DMS - d) * 100),6));s = Math.Round(((Math.Round(DMS * 100, 8) - Math.Floor(Math.Round(DMS * 100,8))) * 100), 8);return (d, m, s);}//格式轉換public double JudgementQuadrant(double Theta, int i, int j) //判斷方位角象限{double CA = 0;double m = rdatas[i].X - rdatas[j].X;double n = rdatas[i].Y - rdatas[j].Y;if (m > 0 && n >= 0){CA = Theta;}else if (m <= 0 && n > 0){CA = Math.PI - Theta;}else if (m < 0 && n <= 0){CA = Theta + Math.PI;}else if (m > 0 && n < 0){CA = 2 * Math.PI - Theta;}else if (m == 0 && n > 0){CA = Math.PI / 2;}else if (m == 0 && n < 0){CA = Math.PI * 1.5;}return CA;}public int[] AngularCarry(int d, int m, int s)//角度進位{if (s >= 60){s -= 60;m += 1;}else if (m >= 60){m -= 60;d += 1;}else if (s < 0){s += 60;m -= 1;}else if (m < 0){m += 60;d -= 1;}return new int[] { d, m, s };}public double VDistribution(double s, int i)//改正數分配{double temp2 = 0;//閉合if (form2.radioButton1.Checked){ArrayList arrayList = new ArrayList();int n = 0;if (form2.comboBox1.Text == "兩個已知點"){n = rdatas.Count - 2;for (int j = 1; j < rdatas.Count - 1; j++){arrayList.Add(rdatas[j].L);arrayList.Sort();}}else if (form2.comboBox1.Text == "一個已知點+方位角"){n = rdatas.Count - 1;for (int j = 1; j < rdatas.Count ; j++){arrayList.Add(rdatas[j].L);arrayList.Sort();}}int temp = Convert.ToInt32(Math.Round(tolerance.fβ, 5) % n);//取余int temp1 = Math.Abs(temp);double avernum = (tolerance.fβ - temp) / n;if (temp != 0){if (rdatas[i].L >= Convert.ToDouble(arrayList[n - temp1])){rtdatas[i].V = -(temp / temp1 + avernum);temp2 = s + rtdatas[i].V;}else{rtdatas[i].V = -(avernum);temp2 = s + rtdatas[i].V;}}else{rtdatas[i].V = -(tolerance.fβ / n);temp2 = s + rtdatas[i].V;}}//附和 else if (form2.radioButton2.Checked){int n=rtdatas.Count-2;int temp = Convert.ToInt32(Math.Round(tolerance.fβ, 5) % n);//取余int temp1 = Math.Abs(temp);double avernum = (tolerance.fβ - temp) / n;ArrayList arrayList = new ArrayList();for (int j = 1; j < rdatas.Count - 1; j++){arrayList.Add(rdatas[j].L);arrayList.Sort();}if (temp != 0){if (rdatas[i].L >= Convert.ToDouble(arrayList[n - temp1])){rtdatas[i].V = -(temp / temp1 + avernum);temp2 = s + rtdatas[i].V;}else{rtdatas[i].V = -(avernum);temp2 = s + rtdatas[i].V;}}else{rtdatas[i].V = -(tolerance.fβ / n);temp2 = s + rtdatas[i].V;}}return temp2;}public int[] toDMS(double CA){int d = (int)CA;int m = (int)((CA - d) * 60);int s = (int)Math.Round(((CA - d) * 3600 - m * 60), 0);int[] temp = AngularCarry(d, m, s);return new int[] { temp[0], temp[1], temp[2] };}//十進制度數轉度分秒public double toDu(double d1, double m1, double s1){double du = d1 + m1 / 60 + s1 / 3600;return du;}//度分秒轉十進制度數public void drawPoint(double X, double Y){g.FillRectangle(Brushes.Red, (float)Y, (float)X, 4, 4);}private void 繪圖ToolStripMenuItem_Click(object sender, EventArgs e){tabControl1.SelectedTab = tabControl1.TabPages[2];tabPage3.Show();g = tabPage3.CreateGraphics();midx = tabPage3.ClientRectangle.Height / 2;midy = tabPage3.ClientRectangle.Width / 2;g.DrawLine(Pens.Black, 0, midx, this.ClientRectangle.Width, midx);g.DrawLine(Pens.Black, midy, 0, midy, this.ClientRectangle.Height);curvelist = new List<Point>();int n = 20;for (int i = 0; i < rtdatas.Count; i++){if (i == 0){drawPoint((midx - rtdatas[i].X / n), (midy + rtdatas[i].Y / n));}else{drawPoint((midx - rtdatas[i].X / n), (midy + rtdatas[i].Y / n));g.DrawLine(Pens.Black, (float)(midy + rtdatas[i].Y / n), (float)(midx - rtdatas[i].X /n), (float)(midy + rtdatas[i - 1].Y / n), (float)(midx - rtdatas[i - 1].X / n));}}}private void 保存ToolStripMenuItem_Click(object sender, EventArgs e){//這里的代碼自己搜索一下,就是將datagridview 轉換成txt或者excel}} } //這里是創建的變量class RowData{public string DH;//點號public double DMS;//度分秒public double L;//距離public double X;public double Y;}class ResultData {public string DH;public double HA;//水平角public double V;//改正數public double CHA;//改正后水平角public double CA;//方位角public double L;public double Δx;public double Δy;public double CΔx;public double CΔy;public double X;public double Y;}class Tolerance //限差{public double fβ;public double fl;public double fx;public double fy;public double fD;public double K;}Form2的代碼我就不復制了,如上圖一些設置的按鈕。
五、結語
不管是水準測量平差或者是導線測量,主要面臨的不是公式不會用(高斯正反算就是純粹的將公式套用編程),而是各種編程的基礎問題(數據導入,顯示,分隔,循環處理,debug,輸出等等),計算公式倒是好理解。其實最簡單的就是寫一個最死的程序,只處理一組數據或者單個數據,過后慢慢百度學習,久而久之就相對熟練了。
如果你有基礎,看源碼就可以了。如果你才學C#窗體,我覺得你下載這一個程序或者水準那個基本上可以滿足測繪程序編寫的要求了,不用每個問題都去搜索,這兩個程序基本都包括了。
我才學C#的時候,有很多自己也不會,也要看別人的,比如如何打開文件夾,讀取txt,用逗號或者空格分隔,換行讀取過后再顯示,跨窗體調用數據,保存數據,畫圖,方法的調用等等,遇到了各種報錯了就開始搜索再修改,過后再把它們融合到自己寫的程序。
如果有一個現成的程序,會對你的程序學習有很大幫助。
我的其他文章:
總結
以上是生活随笔為你收集整理的利用C#编写一个附和闭合导线平差程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 简述导线平差计算的五个步骤_附合导线平差
- 下一篇: 闭合导线计算matlab代码,【求助】闭