public static double juli(Point1 pt1, Point1 pt2) { double juli; juli = Math.Sqrt((pt2.X - pt1.X) * (pt2.X - pt1.X) + (pt2.Y - pt1.Y) * (pt2.Y - pt1.Y)); return(juli); }
public static double fangwei(Point1 pt1, Point1 pt2) { double fangweijiao; fangweijiao = 180 - 90 * Math.Abs(pt2.Y - pt1.Y) / (pt2.Y - pt1.Y + Math.Pow(10, -10)) - Math.Atan((pt2.X - pt1.X) / (pt2.Y - pt1.Y + Math.Pow(10, -10))) * 180 / Math.PI; return(fangweijiao * Math.PI / 180); }
private void 横断面ToolStripMenuItem_Click(object sender, EventArgs e) { try { HDM = new List <List <Point1> >(); #region 横断面中心点信息 M = new Point1[n]; for (int i = 0; i < n; i++) { M[i] = new Point1(); M[i].dianhao = "M " + (i + 1); M[i].licheng = 25; M[i].X = (K[i].X + K[i + 1].X) / 2; M[i].Y = (K[i].Y + K[i + 1].Y) / 2; fangwei[i] = fangwei[i] - Math.PI / 2;//跟书上公式不一样 } #endregion //MessageBox.Show(M[0].X.ToString()); #region 横断面插值坐标 for (int i = 0; i < n; i++) { int k = 0; HDM1 = new List <Point1>(); //不知道为什么不能用clear for (int j = -25; j <= 25; j = j + 5) //延伸25米 { if (j != 0) { Point1 p = new Point1(); p.dianhao = "C" + (j / 5); p.licheng = k; p.X = M[i].X + j * Math.Cos(fangwei[i]); p.Y = M[i].Y + j * Math.Sin(fangwei[i]); HDM1.Add(p); } else { HDM1.Add(M[i]); } k = k + 5; } //MessageBox.Show(HDM1[10].X.ToString()); HDM.Add(HDM1); //MessageBox.Show(HDM[0][10].X.ToString()); } #endregion #region 横断面内插高程 for (int i = 0; i < n; i++) { double d; int dianhao = 0; for (int j = 0; j < HDM[i].Count; j++)//对每个内插点都进行计算 { double dmin1 = 0; double HD = 0, LD = 0; //计算插值点高程 for (int q = 0; q < 5; q++) //寻找最近的5个点 { double dmin = 1000000000000; for (int q1 = 0; q1 < point1.Length; q1++)//遍历所有散点 { d = caculate.juli(HDM[i][j], point1[q1]); if (dmin > d && d > dmin1) { dmin = d; dianhao = q1; } } dmin1 = dmin;//存储最小值,次小值,方便排序 //MessageBox.Show(dmin.ToString()); HD = HD + point1[dianhao].Z / dmin; LD = LD + 1 / dmin; } HDM[i][j].Z = HD / LD; } } //MessageBox.Show(HDM1[10].X.ToString()); #endregion #region 横断面面积 double[] S = new double[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < HDM[i].Count - 1; j++) { S[i] = S[i] + ((HDM[i][j].Z + HDM[i][j + 1].Z - 2 * gaocheng) * 5 / 2); } } #endregion #region 计算报告 richTextBox1.Text += "横断面信息\n------------------------------------------------------------\n"; for (int i = 0; i < n; i++) { richTextBox1.Text += "横断面: " + (i + 1) + "\n------------------------------\n"; richTextBox1.Text += "横断面面积: " + Math.Round(S[i], 3) + "\n"; richTextBox1.Text += "横断面全长: " + 50 + "\n"; richTextBox1.Text += "线路主点:\n"; richTextBox1.Text += "点名 \t里程K(m) \tX坐标(m) \tY坐标(m) \tH坐标(m)\n"; for (int j = 0; j < HDM[i].Count; j++) { string str1; string[] str = new string[5]; str[0] = string.Format("{0,-8}", HDM[i][j].dianhao); str[1] = string.Format("{0,-8}", Math.Round(HDM[i][j].licheng, 3)); str[2] = string.Format("{0,-8}", Math.Round(HDM[i][j].X, 3)); str[3] = string.Format("{0,-8}", Math.Round(HDM[i][j].Y, 3)); str[4] = string.Format("{0,-8}", Math.Round(HDM[i][j].Z, 3)); str1 = string.Join("\t", str); richTextBox1.Text += str1 + "\n\n"; } } #endregion } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void 纵断面ToolStripMenuItem_Click(object sender, EventArgs e) { ZDM = new List <Point1>();//列表必须初始化,数组在使用前必须规定其大小 dataGridView1.AllowUserToAddRows = false; #region 数据导入 try { string[] dian; //纵断面关键点 dian = txt_dianming.Text.Split(','); n = dian.Length - 1; //纵断面段数 gaocheng = Convert.ToDouble(txt_gaocheng.Text); point1 = new Point1[dataGridView1.Rows.Count]; //先规定点数组大小 K = new Point1[dian.Length]; for (int i = 0; i < dataGridView1.Rows.Count; i++) { point1[i] = new Point1();//实例化一个点 point1[i].dianhao = dataGridView1.Rows[i].Cells[0].Value.ToString(); point1[i].X = Convert.ToDouble(dataGridView1.Rows[i].Cells[1].Value.ToString().Replace(" ", "")); point1[i].Y = Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value.ToString().Replace(" ", "")); point1[i].Z = Convert.ToDouble(dataGridView1.Rows[i].Cells[3].Value.ToString().Replace(" ", "")); for (int j = 0; j < dian.Length; j++) { if (point1[i].dianhao == dian[j])//寻找关键点并储存 { K[j] = new Point1(); K[j].dianhao = point1[i].dianhao; K[j].X = point1[i].X; K[j].Y = point1[i].Y; K[j].Z = point1[i].Z; } } } } catch { MessageBox.Show("请输入正确的数据!"); return; } //MessageBox.Show(K.Length.ToString()); #endregion try { #region 纵断面内插点平面坐标 fangwei = new double[n]; //存储纵断面方位角信息 licheng = new double[n]; //存储纵断面距离信息 K[0].licheng = 0; int k = 0; for (int i = 0; i < n; i++)//关键点里程 { fangwei[i] = caculate.fangwei(K[i], K[i + 1]); K[i + 1].licheng = K[i].licheng + caculate.juli(K[i], K[i + 1]); licheng[i] = K[i + 1].licheng; while (true) { k = k + 10;//纵断面内插间距为10米 if (k < licheng[i]) { Point1 p1 = new Point1(); p1.dianhao = "V-" + (k / 10); p1.licheng = k; p1.X = K[i].X + (p1.licheng - K[i].licheng) * Math.Cos(fangwei[i]); p1.Y = K[i].Y + (p1.licheng - K[i].licheng) * Math.Sin(fangwei[i]); ZDM.Add(p1); } else { k = k - 10; break; } } } //MessageBox.Show(ZDM.Count.ToString()); #endregion #region 纵断面内插点高程 double d; int dianhao = 0; for (int i = 0; i < ZDM.Count; i++)//对每个内插点都进行计算 { double dmin1 = 0; double HD = 0, LD = 0; //计算插值点高程 for (int q = 0; q < 5; q++) //寻找最近的5个点 { double dmin = 1000000000000; for (int j = 0; j < point1.Length; j++)//遍历所有散点 { d = caculate.juli(ZDM[i], point1[j]); if (dmin > d && d > dmin1) { dmin = d; dianhao = j; } } dmin1 = dmin; //MessageBox.Show(dmin.ToString()); HD = HD + point1[dianhao].Z / dmin; LD = LD + 1 / dmin; } ZDM[i].Z = HD / LD; } #endregion #region 纵断面面积 ZDM.Add(K[n]); for (int i = n - 1; i > 0; i--) { for (int j = ZDM.Count - 1; j > 0; j--) { if (K[i].licheng > ZDM[j].licheng) { ZDM.Insert(j + 1, K[i]); break; } } } ZDM.Insert(0, K[0]); //MessageBox.Show(ZDM.Count.ToString()); double S = 0; for (int i = 0; i < ZDM.Count - 1; i++) { S = S + ((ZDM[i].Z + ZDM[i + 1].Z - 2 * gaocheng) * 10 / 2); } #endregion #region 计算报告 richTextBox1.Text = "纵横断面计算结果\n\n"; richTextBox1.Text += "纵断面信息\n------------------------------------------------------------\n"; richTextBox1.Text += "纵断面面积: " + Math.Round(S, 3) + "\n"; richTextBox1.Text += "纵断面全长: " + Math.Round(licheng.Max(), 3) + "\n"; richTextBox1.Text += "线路主点:\n"; richTextBox1.Text += "点名 \t里程K(m) \tX坐标(m) \tY坐标(m) \tH坐标(m)\n"; for (int i = 0; i < ZDM.Count; i++) { string str1; string[] str = new string[5]; str[0] = string.Format("{0,-8}", ZDM[i].dianhao); str[1] = string.Format("{0,-8}", Math.Round(ZDM[i].licheng, 3)); str[2] = string.Format("{0,-8}", Math.Round(ZDM[i].X, 3)); str[3] = string.Format("{0,-8}", Math.Round(ZDM[i].Y, 3)); str[4] = string.Format("{0,-8}", Math.Round(ZDM[i].Z, 3)); str1 = string.Join("\t", str); richTextBox1.Text += str1 + "\n\n"; } #endregion } catch (Exception ex) { MessageBox.Show(ex.Message); } }