/// <summary> /// 生成初始矩形 /// </summary> /// <param name="p"></param> /// <returns></returns> private Tpoint[] Build_Matrix(Tpoint[] p) { double[] X = new double[p.Length]; double[] Y = new double[p.Length]; for (int i = 0; i < p.Length; i++) { X[i] = p[i].x; Y[i] = p[i].y; } double Xmin, Xmax, Ymin, Ymax; Xmin = X.Min(); Xmax = X.Max(); Ymax = Y.Max(); Ymin = Y.Min(); Tpoint[] Matrix = new Tpoint[4]; Matrix[0] = new Tpoint(); Matrix[0].Name = "P1"; Matrix[0].x = Xmin - 1; Matrix[0].y = Ymin - 1; Matrix[1] = new Tpoint(); Matrix[1].Name = "P2"; Matrix[1].x = Xmin - 1; Matrix[1].y = Ymax + 1; Matrix[2] = new Tpoint(); Matrix[2].Name = "P3"; Matrix[2].x = Xmax + 1; Matrix[2].y = Ymax + 1; Matrix[3] = new Tpoint(); Matrix[3].Name = "P4"; Matrix[3].x = Xmax + 1; Matrix[3].y = Ymin - 1; return(Matrix); }
public Triangle(Tpoint p1, Tpoint p2, Tpoint p3, double hr) { this.p1 = p1; this.p2 = p2; this.p3 = p3; this.hr = hr; SetV(); }
/// <summary> /// 打开文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripButton2_Click(object sender, EventArgs e) { try { InputGrid(); tpoints = new Tpoint[data.RowCount]; for (int i = 0; i < data.RowCount; i++) { tpoints[i] = new Tpoint(i + 1, data[0, i].Value.ToString(), double.Parse(data[1, i].Value.ToString()), double.Parse(data[2, i].Value.ToString()), double.Parse(data[3, i].Value.ToString())); } GetPic_Point(zoom, go[1]); } catch { MessageBox.Show("打开数据失败"); } }
public Triangle(Tpoint p1, Tpoint p2, Tpoint p3) { this.p1 = p1; this.p2 = p2; this.p3 = p3; }
public Side(Tpoint p1, Tpoint p2) { this.p1 = p1; this.p2 = p2; }
public Side(Tpoint p1, Tpoint p2, double hr) { this.p1 = p1; this.p2 = p2; this.hr = hr; }
/// <summary> /// 通过遍历离散点,生成平面三角网 /// </summary> /// <param name="p"></param> /// <param name="T1"></param> /// <param name="S"></param> /// <returns></returns> private List <Tpoint> BuildTrinet(Tpoint[] p, List <Tpoint> T1) { List <Tpoint> T2 = new List <Tpoint>(); List <Side> S = new List <Side>(); for (int i = 0; i < p.Length; i++) { for (int j = 0; j < T1.Count - 2; j += 3) { Tpoint A = new Tpoint { x = T1[j].x, y = T1[j].y }; Tpoint B = new Tpoint { x = T1[j + 1].x, y = T1[j + 1].y }; Tpoint C = new Tpoint { x = T1[j + 2].x, y = T1[j + 2].y }; double x0, y0, r, lr; x0 = ((B.y - A.y) * (C.y * C.y - A.y * A.y + C.x * C.x - A.x * A.x) - (C.y - A.y) * (B.y * B.y - A.y * A.y + B.x * B.x - A.x * A.x)) / (2 * (C.x - A.x) * (B.y - A.y) - 2 * (B.x - A.x) * (C.y - A.y)); y0 = ((B.x - A.x) * (C.x * C.x - A.x * A.x + C.y * C.y - A.y * A.y) - (C.x - A.x) * (B.x * B.x - A.x * A.x + B.y * B.y - A.y * A.y)) / (2 * (C.y - A.y) * (B.x - A.x) - 2 * (B.y - A.y) * (C.x - A.x)); r = Math.Sqrt((x0 - A.x) * (x0 - A.x) + (y0 - A.y) * (y0 - A.y)); lr = Math.Sqrt((p[i].x - x0) * (p[i].x - x0) + (p[i].y - y0) * (p[i].y - y0)); //P点到外接圆圆心的距离 if (lr < r) //P点在三角形ABC外接圆的内部 { T2.Add(T1[j]); T2.Add(T1[j + 1]); T2.Add(T1[j + 2]); T1.RemoveAt(j + 2); T1.RemoveAt(j + 1); T1.RemoveAt(j); j -= 3; } }//遍历T1中全部三角形 //三角形用3点排列变为3边排列 for (int k = 0; k < T2.Count; k++) { Side si; if (k % 3 != 2) { si = new Side(T2[k], T2[k + 1]); } else { si = new Side(T2[k], T2[k - 2]); } S.Add(si); } //删除S中的公共边 for (int k = 0; k < S.Count - 1; k++) { int sss = 0; for (int m = k + 1; m < S.Count; m++) { if (S[m] == S[k]) { sss = 1; S.RemoveAt(m); m--; } } if (sss == 1) { S.RemoveAt(k); k--; } } T2.Clear(); for (int k = 0; k < S.Count; k++) { T1.Add(S[k].p1); T1.Add(S[k].p2); T1.Add(p[i]); } S.Clear(); }//遍历所有离散点 return(T1); }