public TopoPolyline(ContourPolyline polyline) { this.ArcID = polyline.PID; Innerid = _ArcID++; MiddlePoint = new List <TopoPoint>(); MBR = new MinBoundRect(); if (polyline.PointList.Count >= 2) { TopoPoint startPoint = new TopoPoint(polyline.PointList.First(), true); startPoint.TopologyArcs.Add(this); this.BeginNode = startPoint; TopoPoint endPoint = new TopoPoint(polyline.PointList.Last(), true); endPoint.TopologyArcs.Add(this); this.EndNode = endPoint; MBR.UpdateRect(startPoint.X, startPoint.Y); MBR.UpdateRect(endPoint.X, endPoint.Y); for (int i = 1; i < polyline.PointList.Count - 1; i++) { if (polyline.PointList[i].OID != startPoint.PointID && polyline.PointList[i].OID != EndNode.PointID) { TopoPoint midPoint = new TopoPoint(polyline.PointList[i], false); MiddlePoint.Add(midPoint); midPoint.TopologyArcs.Add(this); } MBR.UpdateRect(polyline.PointList[i].X, polyline.PointList[i].Y); } } }
//判断点是否在区域内 法2 public static bool IntersectPoint(TopoPoint p1, TopoPoint p2, TopoPoint todeterPoint, TopoPoint rays) { double IntersectX = ((p2.X - p1.X) * (todeterPoint.X - rays.X) * (todeterPoint.Y - p1.Y) - todeterPoint.X * (p2.X - p1.X) * (todeterPoint.Y - rays.Y) + p1.X * (p2.Y - p1.Y) * (todeterPoint.X - rays.X)) / ((p2.Y - p1.Y) * (todeterPoint.X - rays.X) - (p2.X - p1.X) * (todeterPoint.Y - rays.Y)); double IntersectY = ((p2.Y - p1.Y) * (todeterPoint.Y - rays.Y) * (todeterPoint.X - p1.X) - todeterPoint.Y * (p2.Y - p1.Y) * (todeterPoint.X - rays.X) + p1.Y * (p2.X - p1.X) * (todeterPoint.Y - rays.Y)) / ((p2.X - p1.X) * (todeterPoint.Y - rays.Y) - (p2.Y - p1.Y) * (todeterPoint.X - rays.X)); double relativeE1 = 0; if ((p2.X - p1.X) != 0) { relativeE1 = (IntersectX - p1.X) / (p2.X - p1.X); } else { relativeE1 = (IntersectY - p1.Y) / (p2.Y - p1.Y); } if (0 <= relativeE1 && relativeE1 < 1) { return(true); } else { return(false); } }
//获取选中的多边形 public TopoPolygon GetClickPointInsidePolygon(TopoPoint clickPoint) { foreach (var polygon in this.TopoPolygonList) { if (polygon.IfPointInRegion(clickPoint)) { return(polygon); } } return(null); }
//获取另一结点 public TopoPoint GetAnotherNode(TopoPoint p) { if (this.BeginNode.PointID == p.PointID) { return(this.EndNode); } else if (this.EndNode.PointID == p.PointID) { return(this.BeginNode); } else { return(null); } }
//判断是否是结点 public int IsNode(TopoPoint p) { if (this.BeginNode.PointID == p.PointID) { return(1); } else if (this.EndNode.PointID == p.PointID) { return(-1); } else { return(0); } }
//判断点是否在区域内 public bool IfPointInRegion(TopoPoint todeterPoint) { TopoPoint[] points = this.ConvertToPointArray(); TopoPoint rayPoint = new TopoPoint(todeterPoint.X * 2, todeterPoint.Y, todeterPoint.Z, false); int intersectCount = 0; for (int i = 0; i < points.Length - 1; i++) { if (TopoPolygon.IntersectPoint(points[i], points[i + 1], todeterPoint, rayPoint) == true) { intersectCount++; } } return(intersectCount / 2 != 0); }
public TopoPolyline(Edge edge) { this.ArcID = edge.EID; MiddlePoint = new List <TopoPoint>(); MBR = new MinBoundRect(); TopoPoint startPoint = new TopoPoint(edge.StartPoint, true); startPoint.TopologyArcs.Add(this); this.BeginNode = startPoint; TopoPoint endPoint = new TopoPoint(edge.EndPoint, true); endPoint.TopologyArcs.Add(this); this.EndNode = endPoint; MBR.UpdateRect(startPoint.X, startPoint.Y); MBR.UpdateRect(endPoint.X, endPoint.Y); }
public TopoPoint[] ConvertToPointArray() { List <TopoPoint> pointArray = new List <TopoPoint>(); TopoPoint b1 = TopologyArcs[0].BeginNode; TopoPoint e1 = TopologyArcs[0].EndNode; TopoPoint b2 = TopologyArcs.Last().BeginNode; TopoPoint e2 = TopologyArcs.Last().EndNode; TopoPoint beginPoint; if (b1.PointID == b2.PointID) { beginPoint = b1; } else if (b1.PointID == e2.PointID) { beginPoint = b1; } else { beginPoint = e1; } pointArray.Add(beginPoint); for (int i = 0; i < TopologyArcs.Count; i++) { int direct = TopologyArcs[i].IsNode(beginPoint); if (direct > 0) { pointArray.AddRange(TopologyArcs[i].MiddlePoint.ToArray()); } else { List <TopoPoint> middlePoint = TopologyArcs[i].MiddlePoint; for (int k = 0; k < middlePoint.Count; k++) { pointArray.Add(middlePoint[middlePoint.Count - 1 - k]); } } beginPoint = TopologyArcs[i].GetAnotherNode(beginPoint); pointArray.Add(beginPoint); } return(pointArray.ToArray()); }
public TopoPointSet(TopoPolyline[] topoLines) { TopoPointList = new List <TopoPoint>(); TopoNodeList = new List <TopoPoint>(); for (int i = 0; i < topoLines.Length; i++) { for (int j = 0; j < topoLines[i].MiddlePoint.Count; j++) { if (this.IfPointExists(topoLines[i].MiddlePoint[j].PointID) == false) { TopoPointList.Add(topoLines[i].MiddlePoint[j]); } } if (this.IfNodeExists(topoLines[i].BeginNode.PointID) == false) { TopoNodeList.Add(topoLines[i].BeginNode); } else { TopoPoint existPoint = this.GetNodeByPointID(topoLines[i].BeginNode.PointID); if (existPoint.TopologyArcs.Contains(topoLines[i]) == false) { existPoint.TopologyArcs.Add(topoLines[i]); } } if (this.IfNodeExists(topoLines[i].EndNode.PointID) == false) { TopoNodeList.Add(topoLines[i].EndNode); } else { TopoPoint existPoint = this.GetNodeByPointID(topoLines[i].EndNode.PointID); if (existPoint.TopologyArcs.Contains(topoLines[i]) == false) { existPoint.TopologyArcs.Add(topoLines[i]); } } } }
//获取与另一点距离 public double GetDistance(TopoPoint other) { return(Math.Sqrt(Math.Pow(this.X - other.X, 2) + Math.Pow(this.Y - other.Y, 2))); }
/// <summary> /// 获取另一点对于当前点的方位角(角度) /// </summary> /// <param name="p"></param> /// <returns></returns> public double GetPositon(TopoPoint p) { return(this.GetPosition(p.X, p.Y)); }