private static bool isInBuilding(Point p, ref List <TriangleBound> DisAngle) { if (DisAngle == null) { return(false); } int cnt = DisAngle.Count; bool isEdge; int startIndex = 0; for (int i = 0; i < cnt; i++) { List <Point> vertex = BuildingGrid3D.getBuildingVertex(DisAngle[i].buildingid); if (GeometricUtilities.PointInPolygon(vertex.ToArray(), p, out isEdge, ref startIndex)) { return(true); } } return(false); }
/// <summary> /// 相对原点的多边形边界 /// </summary> /// <param name="source"></param> /// <param name="vertex"></param> /// <param name="mintheta"></param> /// <param name="maxtheta"></param> /// <param name="distance"></param> /// <returns></returns> public static bool getBoundPointIndex(Point source, List <Point> vertex, ref TriangleBound tb) { bool isEdge; int startIndex = 0; //原点是否在多边形内部 if (GeometricUtilities.PointInPolygon(vertex.ToArray(), source, out isEdge, ref startIndex)) { return(false); } tb.maxIndex = -1; tb.maxTheta = -1; tb.minIndex = int.MaxValue - 500; tb.minTheta = 1000; tb.totalVertex = vertex.Count; double theta; Dictionary <int, Polar> tmp = new Dictionary <int, Polar>(); int cnt = vertex.Count; Polar p; //求相对原点的极坐标,根据theta角判断边界 for (int i = 0; i < cnt; i++) { p = GeometricUtilities.getPolarCoord(source, vertex[i]); theta = p.theta; tmp.Add(i, p); if (theta < tb.minTheta) { tb.minIndex = i; tb.minTheta = theta; } if (theta > tb.maxTheta) { tb.maxIndex = i; tb.maxTheta = theta; } } //说明多边形与x轴相交 if (tb.maxTheta - tb.minTheta > Math.PI) { double th; tb.maxIndex = -1; tb.maxTheta = -1; tb.minIndex = int.MaxValue - 500; tb.minTheta = 1000; foreach (var kv in tmp) { th = kv.Value.theta; if (th < Math.PI) { if (th > tb.maxTheta) { tb.maxIndex = kv.Key; tb.maxTheta = th; } } else if (th < tb.minTheta) { tb.minIndex = kv.Key; tb.minTheta = th; } } } tb.stob = tmp[tb.minIndex].r > tmp[(tb.minIndex + 1) % cnt].r; return(true); }