public WPolyLine2D(List <WPoint2D> Ps, ref WGeometry2D WGC) { this._startpoint = Ps[0]; this._endpoint = Ps[Ps.Count - 1]; this.WGC = WGC; this.Vertexs = Ps; if (this.Vertexs.First().Equals(this.Vertexs.Last(), WGeos2D_Paras.E_Merge)) { this.Vertexs.RemoveAt(0); } this.Vertexs_Len = new List <double>(); this._length = 0; for (int i = 0; i < this.Vertexs.Count - 1; i++) { this.Vertexs_Len.Add(this.Vertexs[i].DistanceTo(this.Vertexs[i + 1])); this._length += this.Vertexs_Len[i]; } _xmin = double.MaxValue; _xmax = double.MinValue; _ymin = double.MaxValue; _ymax = double.MinValue; for (int i = 0; i < this.Vertexs.Count; i++) { _xmin = Math.Min(_xmin, Vertexs[i].X); _xmax = Math.Max(_xmax, Vertexs[i].X); _ymin = Math.Min(_ymin, Vertexs[i].Y); _ymax = Math.Max(_ymax, Vertexs[i].Y); } this.Nodes = new List <WPoint2D>(); this.Nodes_num = new List <int>(); this.Free_Check = true; }
private static void Read_SingleEntitie(ref StreamReader sr, ref WGeometry2D WGO) { string Kind = sr.ReadLine(); switch (Kind) { case "Line": Read_Line(ref sr, ref WGO); break; case "PolyLine": Read_PolyLine(ref sr, ref WGO); break; case "Circle": Read_Circle(ref sr, ref WGO); break; case "Text": //Read_Text(ref sr, ref WGO); break; default: while (true) { if (sr.ReadLine() == "End") { break; } } break; } }
/// 从wgo文件输入实体,添加至WGO中 /// <summary> /// 从wgo文件输入实体,添加至WGO中 /// </summary> /// <returns>true表示文件包含参数,false表示文件不包含参数</returns> public static bool Read_WGeoFile(WGeometry2D WGO, ref StreamReader sr) { sr.ReadLine(); sr.ReadLine(); string t = sr.ReadLine(); while (t != "*****************") { if (t == "") { continue; } if (t[0] == '*') { continue; } if (t == "Start") { Read_SingleEntitie(ref sr, ref WGO); } t = sr.ReadLine(); } if (sr.Peek() == -1) { return(false); } else { return(true); } }
private static void Read_Line(ref StreamReader sr, ref WGeometry2D WGC) { tLayer = sr.ReadLine(); t_1 = sr.ReadLine().Split(','); tColor = Color.FromArgb(Convert.ToInt16(t_1[0]), Convert.ToInt16(t_1[1]), Convert.ToInt16(t_1[2])); tWidth = Convert.ToSingle(sr.ReadLine()); t_1 = sr.ReadLine().Split(','); x1 = Convert.ToDouble(t_1[0]); y1 = Convert.ToDouble(t_1[1]); t_1 = sr.ReadLine().Split(','); x2 = Convert.ToDouble(t_1[0]); y2 = Convert.ToDouble(t_1[1]); ///// if (Math.Abs(x1 - x2) <= WGeos2D_Paras.E_Merge && Math.Abs(y1 - y2) <= WGeos2D_Paras.E_Merge) { sr.ReadLine(); return; } WLine2D L = new WLine2D(WGC.PsList.Add(x1, y1, true), WGC.PsList.Add(x2, y2, true)); L.Kind = GeoKind.Line; L.Layer = tLayer; L.Color = tColor; L.LineWidth = tWidth; L.Sort = ShowSort._5; WGC.Add_Geo(L); sr.ReadLine(); }
private static List <int>[] Get_Rims(ref WEntity2D[] Cs, ref WGeometry2D WGC) { List <int>[] Rims = new List <int> [0]; /////用于输出的所有的圈圈 List <int>[] Ns = new List <int> [0]; /////每个节点相连的节点的编号 int[][] Ls = new int[Cs.Length][]; /////每条线的头尾节点编号 List <WVector2D>[] Vs = new List <WVector2D> [0]; /////每个节点连接对应节点时的线的向量 List <PAngle>[] As = new List <PAngle> [0]; /////每个节点与对应节点连接的内夹角,连接几个点就有几个内夹角 ///// P2Ps_Connection(ref Cs, ref WGC, ref Ls, ref Ns, ref Vs); /////求出点点之间的关系 P2Ps_Angles(ref Ns, ref Vs, ref As); /////求出每个点的内夹角 ///从自由节点开始层层剖分 List <int> Rimt; /////计算时使用的单个Rim,若该Rim不正确则不会被输出 int Npo = 0; /////某一次的扫描起点节点编号 int Check_Num = -1; /////不能够形成正确Rim的节点的编号 ///// int Qrim = 0; while (true) /////for (int k = 0; k < 30;k++ ) { Qrim = Rims.Length; Npo = -1; for (int i = 0; i < Ns.Length; i++) { if (As[i].Count > 0 && i > Check_Num) { Npo = i; break; } } if (Npo == -1) { break; /////如果找不到有连线的节点则不要继续了 } ///// Rimt = Create_SingleRim(Npo, ref Ns, ref As); /////创建一个Rim if (Check_RimtValid(ref Rimt, ref Ns) == false) /////判断Rimt是否可用 { Check_Num = Npo; /////如果这个圈圈是无效的,则在开始搜索时把这个节点排除 continue; /////从这点的下一编号点开始 } Check_Num = -1; ///// Update_As(ref Rimt, ref Rims, ref As); /////将已经Check后OK的Rimt输入,并更新Ns数组 if (Rims.Length == Qrim) { break; /////此时的Rims是节点集合,而不是线的集合 } } ///// Convert_Rims2Ls(ref Rims, ref Ls); /////将Rims由点点连接转换为线线连接 Delete_Repeat(ref Rims); return(Rims); }
/// 根据图层和颜色选择 public static WEntity2D[] SelectLines(string layername, Color color, ref WGeometry2D WGC) { WEntity2D[] Out = new WEntity2D[0]; for (int i = 0; i < WGC.Entities.Count; i++) { if (WGC.Entities[i].Layer == layername && WGC.Entities[i].Color.R == color.R && WGC.Entities[i].Color.G == color.G && WGC.Entities[i].Color.B == color.B) { Array.Resize <WEntity2D>(ref Out, Out.Length + 1); Out[Out.Length - 1] = WGC.Entities[i]; } } return(Out); }
public static List <int>[] Get_Rims(ref WEntity2D[] Cs, ref WGeometry2D WGC) { List <int>[] Ns = new List <int> [0]; /////每个节点相连的节点的编号 List <int>[] Rims = new List <int> [0]; /////用于输出的所有的圈圈 int[][] Ls = new int[Cs.Length][]; /////每条线的头尾节点编号 double[] Xs = new double[0]; /////每个节点的X坐标 double[] Ys = new double[0]; /////每个节点的Y坐标 ///// P2Ps_Connection(ref Cs, ref WGC, /////求出点点之间的关系 ref Xs, ref Ys, ref Ns, ref Ls); ///从自由节点开始层层剖分 List <int> Rimt; /////计算时使用的单个Rim,若该Rim不正确则不会被输出 int Npo = 0; /////某一次的扫描起点节点编号 int Check_Num = -1; /////不能够形成正确Rim的节点的编号 ///// while (true) { Npo = -1; for (int i = 0; i < Ns.Length; i++) { if (Ns[i].Count == 2 && i > Check_Num) { Npo = i; break; } } if (Npo == -1) { break; /////如果找不到有连线的自由节点则不要继续了 } ///// Rimt = Create_SingleRim(Npo, ref Ns); /////创建一个Rim ///// if (Check_RimtValid(ref Rimt, ref Ns) == false) /////判断Rimt是否可用 { Check_Num = Npo; /////如果这个圈圈是无效的,则在开始搜索时把这个节点排除 continue; /////从这点的下一编号点开始 } Check_Num = -1; ///// Update_Ns(ref Rimt, ref Ns, ref Rims); /////将已经Check后OK的Rimt输入,并更新Ns数组 /////此时的Rims是节点集合,而不是线的集合 } ///// Convert_Rims2Ls(ref Rims, ref Ls); /////将Rims由点点连接转换为线线连接 ///// //Output(ref sw, ref Xs, ref Ys, ref Ns, ref Rims, ref Ls); /////输出 return(Rims); }
public void SetWGeo2DDatas(WGeometry2D WGC, bool Update_Bound) { Entities = WGC.Entities; PsList = WGC.PsList; if (Update_Bound == false) { return; } this.Bounds = new BoundingBox( (float)WGC.Bounds.Xmin, (float)WGC.Bounds.Xmax, (float)WGC.Bounds.Ymin, (float)WGC.Bounds.Ymax); }
public WCircle2D(WPoint2D Center, double R, ref WGeometry2D WGC) { this.WGC = WGC; _center = Center; _startpoint = new WPoint2D(0, 0); _endpoint = new WPoint2D(0, 0); _r = R; GetLength(); _xmin = Center.X - R; _xmax = Center.X + R; _ymin = Center.Y - R; _ymax = Center.Y + R; }
private static void Read_PolyLine(ref StreamReader sr, ref WGeometry2D WGC) { tLayer = sr.ReadLine(); t_1 = sr.ReadLine().Split(','); tColor = Color.FromArgb(Convert.ToInt16(t_1[0]), Convert.ToInt16(t_1[1]), Convert.ToInt16(t_1[2])); tWidth = Convert.ToSingle(sr.ReadLine()); int Q = Convert.ToInt32(sr.ReadLine()); tPs = new List <WPoint2D>(); tPst = new WPoint2D[Q]; for (int i = 0; i < Q; i++) { t_1 = sr.ReadLine().Split(','); tPst[i] = new WPoint2D(Convert.ToDouble(t_1[0]), Convert.ToDouble(t_1[1])); } tPs.Add(WGC.PsList.Add(tPst[0].X, tPst[0].Y, true)); for (int i = 1; i < Q - 1; i++) { if (Near_Check(tPst[i], tPst[i - 1]) == false && Near_Check(tPst[i], tPst[i + 1]) == false) { tPs.Add(WGC.PsList.Add(tPst[i].X, tPst[i].Y, false)); } } tPs.Add(WGC.PsList.Add(tPst[Q - 1].X, tPst[Q - 1].Y, true)); tPst = null; ///// if (tPs.Count < 2) { sr.ReadLine(); return; } WPolyLine2D PL = new WPolyLine2D(tPs, ref WGC); PL.Kind = GeoKind.PolyLine; PL.Layer = tLayer; PL.Color = tColor; PL.LineWidth = tWidth; PL.Sort = ShowSort._5; WGC.Add_Geo(PL); sr.ReadLine(); }
private static void Read_Circle(ref StreamReader sr, ref WGeometry2D WGC) { tLayer = sr.ReadLine(); t_1 = sr.ReadLine().Split(','); tColor = Color.FromArgb(Convert.ToInt16(t_1[0]), Convert.ToInt16(t_1[1]), Convert.ToInt16(t_1[2])); tWidth = Convert.ToSingle(sr.ReadLine()); t_1 = sr.ReadLine().Split(','); x1 = Convert.ToDouble(t_1[0]); y1 = Convert.ToDouble(t_1[1]); x2 = Convert.ToDouble(sr.ReadLine()); WCircle2D C = new WCircle2D(WGC.PsList.Add(x1, y1, true), x2, ref WGC); C.Kind = GeoKind.Circle; C.Layer = tLayer; C.Color = tColor; C.LineWidth = tWidth; C.Sort = ShowSort._5; WGC.Add_Geo(C); sr.ReadLine(); }
/// <summary> /// 在世界中加入线的编号 /// </summary> /// <param name="Curves"></param> /// <param name="WGC"></param> private static void Add_CurveNum(ref WEntity2D[] Curves, ref WGeometry2D WGC) { string N; WPoint2D S, E; int A; WPoint2D P = new WPoint2D(); for (int i = 0; i < Curves.Length; i++) { N = Convert.ToString(i); if (Curves[i].Kind == GeoKind.Line) { S = ((WCurve2D)Curves[i]).StartPoint; E = ((WCurve2D)Curves[i]).EndPoint; P = new WPoint2D((S.X + E.X) / 2, (S.Y + E.Y) / 2); } if (Curves[i].Kind == GeoKind.PolyLine) { A = ((WPolyLine2D)Curves[i]).Count / 2; P = ((WPolyLine2D)Curves[i])[A]; } WGC.Add_Geo(new WText2D(N, P, 10)); } }
public static List <WPoint2D> DotCurve_Times(WEntity2D C, WPoint2D P1, WPoint2D P2, int Times, ref WGeometry2D WGC) { if (Times == 0 || Times == 1) { List <WPoint2D> Out = new List <WPoint2D>(); Out.Add(((WCurve2D)C).StartPoint); Out.Add(((WCurve2D)C).EndPoint); return(Out); } if (C.Kind == GeoKind.Line) { return(Dotline_Times((WLine2D)C, P1, P2, Times)); } return(DotPolyline_Times((WPolyLine2D)C, P1, P2, Times, ref WGC)); }
private static List <WPoint2D> DotPolyline_Times(WPolyLine2D PL, WPoint2D P1, WPoint2D P2, int Times, ref WGeometry2D WGC) { ///求取最近点 WPoint2D p1 = (WPoint2D)Geos2D_Other.ClosestPoint_P2PL(P1, PL, true); WPoint2D p2 = (WPoint2D)Geos2D_Other.ClosestPoint_P2PL(P2, PL, true); if (p1.CheckNum > p2.CheckNum) ///如果p2排在p1之前,需要对换位置 { WPoint2D p = p1; p1 = p2; p2 = p; } List <WPoint2D> Ps = new List <WPoint2D>(); Ps.Add(p1); for (int i = p1.CheckNum + 1; i <= p2.CheckNum; i++) { Ps.Add(PL[i]); } Ps.Add(p2); WPolyLine2D PL2 = new WPolyLine2D(Ps, ref WGC); return(DotPolyline_Times(PL2, Times)); }
private static void Read_Text(ref StreamReader sr, ref WGeometry2D WGO) { tLayer = sr.ReadLine(); t_1 = sr.ReadLine().Split(','); tColor = Color.FromArgb(Convert.ToInt16(t_1[0]), Convert.ToInt16(t_1[1]), Convert.ToInt16(t_1[2])); }
public Form_Main() { WMC = new List <WMesh2D_Mesh>(); WGC = new WGeometry2D(); InitializeComponent(); }
public WArc2D(WPoint2D Center, WPoint2D StartPoint, WPoint2D EndPoint, bool Direction, ref WGeometry2D WGC) { this.WGC = WGC; _center = Center; _startpoint = StartPoint; _endpoint = EndPoint; _direction = Direction; GetLength(); }
/// 求出点点之间的关系 private static void P2Ps_Connection(ref WEntity2D[] Cs, ref WGeometry2D WGC, ref int[][] Ls, ref List <int>[] Ns, ref List <WVector2D>[] Vs) { double[] Xs = new double[0]; /////每个节点的X坐标 double[] Ys = new double[0]; /////每个节点的Y坐标 bool c; ////判断某个节点是否可以输入,默认为true,重复则输入false WPoint2D[] Pt = new WPoint2D[2]; double x, y; int Q; /// for (int i = 0; i < Cs.Length; i++) { Ls[i] = new int[2]; Pt[0] = ((WCurve2D)Cs[i]).StartPoint; /////处理起点 Pt[1] = ((WCurve2D)Cs[i]).EndPoint; /////处理起点 for (int j = 0; j < 2; j++) { c = false; x = Pt[j].X; y = Pt[j].Y; for (int k = 0; k < Xs.Length; k++) { if (Math.Abs(x - Xs[k]) < WGeos2D_Paras.E_Merge && Math.Abs(y - Ys[k]) < WGeos2D_Paras.E_Merge) { Ls[i][j] = k; Ns[k].Add(i); /////如果该点和已知点距离在误差范围内,在已有节点的连接单元编号后面加上该线的编号 /////此时Ns表示每个节点相连的线的编号 c = true; break; } } if (c == false) { Q = Ns.Length + 1; Array.Resize <List <int> >(ref Ns, Q); Array.Resize <double>(ref Xs, Q); Array.Resize <double>(ref Ys, Q); Xs[Q - 1] = x; Ys[Q - 1] = y; Ns[Q - 1] = new List <int>(); Ns[Q - 1].Add(i); Ls[i][j] = Q - 1; } } } ////// int Nl; Vs = new List <WVector2D> [Ns.Length]; /////此时将Ns转换为每个节点相连的节点的编号 for (int i = 0; i < Ns.Length; i++) { Vs[i] = new List <WVector2D>(); for (int j = 0; j < Ns[i].Count; j++) { Nl = Ns[i][j]; if (Ls[Nl][0] == i) { Ns[i][j] = Ls[Nl][1]; Vs[i].Add(((WCurve2D)Cs[Nl]).Direction_Head); } else { Ns[i][j] = Ls[Nl][0]; Vs[i].Add(((WCurve2D)Cs[Nl]).Direction_Tail); } } } }
///// public void SetWGeo2DDatas(WGeometry2D WGC) { SetWGeo2DDatas(WGC, true); }