private void 反算ToolStripMenuItem_Click(object sender, EventArgs e) { zf = -1; initialize(); dataGridView1.AllowUserToAddRows = false; #region 数据导入 try { for (int i = 0; i < dataGridView1.Rows.Count; i++) { B1.Add(Caculates.dmstohudu(Convert.ToDouble(dataGridView1.Rows[i].Cells[1].Value))); //(-90~90) L1.Add(Caculates.dmstohudu(Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value))); //(0~360) B2.Add(Caculates.dmstohudu(Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value))); //(0~360) L2.Add(Caculates.dmstohudu(Convert.ToDouble(dataGridView1.Rows[i].Cells[5].Value))); } } catch { MessageBox.Show("请输入正确的数据!"); return; } #endregion #region 反算 for (int i = 0; i < dataGridView1.Rows.Count; i++) { double u1, u2, a1, a2, b1, b2;//辅助量 double p, q, l0, l, dl, gl = 0, gl0; double a12, sin_d, cos_d, d, M, sin_m, cos_m; double kk2, kk4, e14, e16, aaf, bbf, ccf; //定义球面计算变量 double k2, k4, k6, af, bf, cf; //定义迭代变量,求边长归化量 #region 计算辅助量 u1 = Math.Atan(Math.Sqrt(1 - e1) * Math.Tan(B1[i])); //归化纬度 u2 = Math.Atan(Math.Sqrt(1 - e1) * Math.Tan(B2[i])); l = L2[i] - L1[i]; //椭球面经差 a1 = Math.Sin(u1) * Math.Sin(u2); a2 = Math.Cos(u1) * Math.Cos(u2); b1 = Math.Cos(u1) * Math.Sin(u2); b2 = Math.Sin(u1) * Math.Cos(u2); l0 = l; #endregion #region 计算起点大地方位角 do { gl0 = gl; p = Math.Cos(u2) * Math.Sin(l0);//第一次计算时先以椭球面经差代替球面经差 q = b1 - b2 * Math.Cos(l0); a12 = Math.Atan(p / q); if (p > 0) { if (q > 0) { a12 = Math.Abs(a12); } else { a12 = Math.PI - Math.Abs(a12); } } else { if (q < 0) { a12 = Math.PI + Math.Abs(a12); } else { a12 = Math.PI * 2 - Math.Abs(a12); } } sin_d = p * Math.Sin(a12) + q * Math.Cos(a12); cos_d = a1 + a2 * Math.Cos(l0); d = Math.Atan(sin_d / cos_d); if (cos_d > 0) { d = Math.Abs(d); } else { d = Math.PI - Math.Abs(d); } sin_m = Math.Cos(u1) * Math.Sin(a12); cos_m = Math.Sqrt(1 - sin_m * sin_m); M = Math.Atan(Math.Tan(u1) / Math.Cos(a12));// kk2 = e1 * cos_m * cos_m; kk4 = kk2 * kk2; e14 = e1 * e1; e16 = e1 * e1 * e1; aaf = (e1 / 2 + e14 / 8 + e16 / 16) - e1 * (1 + e1) * kk2 / 16 + 3 * e1 * kk4 / 128; bbf = e1 * (1 + e1) * kk2 / 16 - e1 * kk4 / 32; ccf = e1 * kk4 / 256; gl = sin_m * (aaf * d + bbf * Math.Sin(d) * Math.Cos(2 * M + d) + ccf * Math.Sin(2 * d) * Math.Cos(4 * M + 2 * d)); l0 = l + gl; dl = Math.Abs(gl - gl0); } while (dl * 206265 > 0.00001); //MessageBox.Show(Caculates.hudutodms(a12).ToString()); A12.Add(a12); #endregion #region 计算大地线长度 k2 = e2 * cos_m * cos_m; k4 = k2 * k2; k6 = k2 * k2 * k2; af = (1 - (k2) / 4 + (7 * k4) / 64 - (15 * k6) / 256) / b; //α bf = k2 / 4 - k4 / 8 + (37 * k6) / 512; //β cf = k4 / 128 - k6 / 128; //γ double s = (d - bf * Math.Sin(d) * Math.Cos(2 * M + d) - cf * Math.Sin(2 * d) * Math.Cos(4 * M + 2 * d)) / af; //MessageBox.Show(s.ToString()); S.Add(s); #endregion #region 计算反方位角 double a21; a21 = Math.Atan(Math.Cos(u1) * Math.Sin(l0) / (b1 * Math.Cos(l0) - b2)); if (a21 < 0) { a21 = a21 + Math.PI * 2; } else if (a21 > Math.PI * 2) { a21 = a21 - Math.PI * 2; } if (a12 < Math.PI && a21 < Math.PI) { a21 = a21 + Math.PI; } if (a12 > Math.PI && a21 > Math.PI) { a21 = a21 - Math.PI; } //MessageBox.Show(Caculates.hudutodms(a21).ToString()); A21.Add(a21); #endregion #region 数据导出 dataGridView1.Rows[i].Cells[6].Value = Math.Round(Caculates.hudutodms(A12[i]), 5);//0.1'' dataGridView1.Rows[i].Cells[7].Value = Math.Round(Caculates.hudutodms(A21[i]), 5); dataGridView1.Rows[i].Cells[8].Value = Math.Round(S[i], 3); #endregion } #endregion #region 计算报告 richTextBox1.Text = "**************************************************\n\n"; richTextBox1.Text += " 大地主题反算\n\n"; richTextBox1.Text += "**************************************************\n\n"; richTextBox1.Text += "----------------------统计数据---------------------\n"; richTextBox1.Text += "计算点对总数 :" + dataGridView1.Rows.Count + "\n"; richTextBox1.Text += "椭球长半轴: " + a + "\n"; richTextBox1.Text += "椭球扁率: " + f + "\n\n"; richTextBox1.Text += "----------------------计算结果---------------------\n"; richTextBox1.Text += "点名 \t纬度(B) \t经度(L) \t大地方位角(A) \t大地线长(S)\n"; for (int i = 0; i < dataGridView1.Rows.Count; i++) { richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[0].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[1].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[2].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[6].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[8].Value) + "\n"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[3].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[4].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[5].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[7].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[8].Value) + "\n\n"; } #endregion }
private void 正算ToolStripMenuItem_Click(object sender, EventArgs e) { zf = 1; initialize(); dataGridView1.AllowUserToAddRows = false; #region 数据导入 try { for (int i = 0; i < dataGridView1.Rows.Count; i++) { B1.Add(Caculates.dmstohudu(Convert.ToDouble(dataGridView1.Rows[i].Cells[1].Value))); //(-90~90) L1.Add(Caculates.dmstohudu(Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value))); //(0~360) A12.Add(Caculates.dmstohudu(Convert.ToDouble(dataGridView1.Rows[i].Cells[3].Value))); //(0~360) S.Add(Convert.ToDouble(dataGridView1.Rows[i].Cells[4].Value)); } } catch { MessageBox.Show("请输入正确的数据!"); return; } #endregion #region 正算 for (int i = 0; i < dataGridView1.Rows.Count; i++) { #region 计算归化纬度辅助函数 double sin_u1, cos_u1, sin_u2, sin_m, cos_m, cot_M, M, tan_l, l, gl;//球面元素变量 double W1 = Math.Sqrt(1 - e1 * Math.Sin(B1[i]) * Math.Sin(B1[i])); sin_u1 = Math.Sin(B1[i]) * Math.Sqrt(1 - e1) / W1; cos_u1 = Math.Cos(B1[i]) / W1; sin_m = cos_u1 * Math.Sin(A12[i]); cos_m = Math.Sqrt(1 - sin_m * sin_m); cot_M = (cos_u1 * Math.Cos(A12[i])) / sin_u1; M = Math.Atan(1 / cot_M); #endregion #region 计算球面长度 double k2, k4, k6, af, bf, cf, d0, d1, ds;//定义迭代变量,求边长归化量 k2 = e2 * cos_m * cos_m; k4 = k2 * k2; k6 = k2 * k2 * k2; af = (1 - (k2) / 4 + (7 * k4) / 64 - (15 * k6) / 256) / b; //α bf = k2 / 4 - k4 / 8 + (37 * k6) / 512; //β cf = k4 / 128 - k6 / 128; //γ d0 = af * S[i]; //迭代初值σ0 do { d1 = af * S[i] + bf * Math.Sin(d0) * Math.Cos(2 * M + d0) + cf * Math.Sin(2 * d0) * Math.Cos(4 * M + 2 * d0); //σ ds = Math.Abs(d1 - d0); d0 = d1; }while (ds * 206265 > 0.00001);//限差0.00001秒(不太清楚10 -10是啥意思) #endregion #region 计算经差改正数 double kk2, kk4, e14, e16, aaf, bbf, ccf;//定义球面计算变量 kk2 = e1 * cos_m * cos_m; kk4 = kk2 * kk2; e14 = e1 * e1; e16 = e1 * e1 * e1; aaf = (e1 / 2 + e14 / 8 + e16 / 16) - e1 * (1 + e1) * kk2 / 16 + 3 * e1 * kk4 / 128; bbf = e1 * (1 + e1) * kk2 / 16 - e1 * kk4 / 32; ccf = e1 * kk4 / 256; //经差改正数 gl = sin_m * (aaf * d1 + bbf * Math.Sin(d1) * Math.Cos(2 * M + d1) + ccf * Math.Sin(2 * d1) * Math.Cos(4 * M + 2 * d1)); #endregion #region 计算终点大地坐标及大地方位角 sin_u2 = sin_u1 * Math.Cos(d1) + cos_u1 * Math.Cos(A12[i]) * Math.Sin(d1); B2.Add(Math.Atan(sin_u2 / (Math.Sqrt(1 - e1) * Math.Sqrt(1 - sin_u2 * sin_u2)))); tan_l = Math.Sin(A12[i]) * Math.Sin(d1) / (cos_u1 * Math.Cos(d1) - sin_u1 * Math.Sin(d1) * Math.Cos(A12[i])); l = Math.Atan(tan_l); if (Math.Sin(A12[i]) > 0) { if (tan_l > 0) { l = Math.Abs(l); } else { l = Math.PI - Math.Abs(l); } } else { if (tan_l < 0) { l = -Math.Abs(l); } else { l = Math.Abs(l) - Math.PI; } } L2.Add(L1[i] + l - gl); double tan_a21, a21; tan_a21 = cos_u1 * Math.Sin(A12[i]) / (cos_u1 * Math.Cos(d1) * Math.Cos(A12[i]) - sin_u1 * Math.Sin(d1)); a21 = Math.Atan(tan_a21); if (Math.Sin(A12[i]) < 0) { if (tan_a21 > 0) { a21 = Math.Abs(a21); } else { a21 = Math.PI - Math.Abs(a21); } } else { if (tan_a21 > 0) { a21 = Math.PI + Math.Abs(a21); } else { a21 = Math.PI * 2 - Math.Abs(a21); } } A21.Add(a21); #endregion #region 数据导出 dataGridView1.Rows[i].Cells[6].Value = Math.Round(Caculates.hudutodms(B2[i]), 5);//0.1'' dataGridView1.Rows[i].Cells[7].Value = Math.Round(Caculates.hudutodms(L2[i]), 5); dataGridView1.Rows[i].Cells[8].Value = Math.Round(Caculates.hudutodms(A21[i]), 5); #endregion } #region 计算报告 richTextBox1.Text = "**************************************************\n\n"; richTextBox1.Text += " 大地主题正算\n\n"; richTextBox1.Text += "**************************************************\n\n"; richTextBox1.Text += "----------------------统计数据---------------------\n"; richTextBox1.Text += "计算点对总数 :" + dataGridView1.Rows.Count + "\n"; richTextBox1.Text += "椭球长半轴: " + a + "\n"; richTextBox1.Text += "椭球扁率: " + f + "\n\n"; richTextBox1.Text += "----------------------计算结果---------------------\n"; richTextBox1.Text += "点名 \t纬度(B) \t经度(L) \t大地方位角(A) \t大地线长(S)\n"; for (int i = 0; i < dataGridView1.Rows.Count; i++) { richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[0].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[1].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[2].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[3].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[4].Value) + "\n"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[5].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[6].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[7].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[8].Value) + "\t"; richTextBox1.Text += string.Format("{0, -8}", dataGridView1.Rows[i].Cells[4].Value) + "\n\n"; } #endregion #endregion }