文章目录
一、前言
本程序是使用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,K
public 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Δy
public 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和Y
public 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,用逗号或者空格分隔,换行读取过后再显示,跨窗体调用数据,保存数据,画图,方法的调用等等,遇到了各种报错了就开始搜索再修改,过后再把它们融合到自己写的程序。
如果有一个现成的程序,会对你的程序学习有很大帮助。
我的其他文章:
- 利用Python编写一个高斯正反算程序:https://blog.csdn.net/Zj1638/article/details/125740379
- 利用C#编写一个高斯正反算程序:https://blog.csdn.net/Zj1638/article/details/125380593
- 利用C#编写一个水准测量近似平差程序:https://blog.csdn.net/Zj1638/article/details/119303957
- 利用C#编写一个GPS高程拟合(二次曲面拟合模型)程序:https://blog.csdn.net/Zj1638/article/details/125752243