//sorts a list of points form a polyline public static List <Point2d> SortPoints(List <Point2d> pointList) { if (!ValidateObject.CheckPointList(pointList)) { return(null); } Point2d cen = PolygonUtility.CentroidOfPoly(Polygon2d.ByPoints(pointList)); Vector2d vecX = new Vector2d(0, 100); List <double> angList = new List <double>(); int[] indList = new int[pointList.Count]; for (int i = 0; i < pointList.Count; i++) { Vector2d CenterToPt = new Vector2d(cen, pointList[i]); double dotValue = vecX.Dot(CenterToPt); double angValue = Math.Atan2(CenterToPt.Y - vecX.Y, CenterToPt.X - vecX.X); angList.Add(angValue); indList[i] = i; } List <int> newIndexList = new List <int>(); newIndexList = BasicUtility.SortIndex(angList); List <Point2d> sortedPointList = new List <Point2d>(); for (int i = 0; i < pointList.Count; i++) { sortedPointList.Add(pointList[newIndexList[i]]); } return(sortedPointList); }
public static Dictionary <string, object> SplitByDistance(Polygon2d polyOutline, Random ran, double distance = 10, int dir = 0, double spacing = 0) { if (!ValidateObject.CheckPoly(polyOutline)) { return(null); } double extents = 5000, spacingProvided; List <Point2d> polyOrig = polyOutline.Points; if (spacing == 0) { spacingProvided = BuildLayout.SPACING; } else { spacingProvided = spacing; } List <Point2d> poly = PolygonUtility.SmoothPolygon(polyOrig, spacingProvided); if (!ValidateObject.CheckPointList(poly)) { return(null); } Dictionary <int, object> obj = PointUtility.PointSelector(ran, poly); Point2d pt = (Point2d)obj[0]; int orient = (int)obj[1]; Line2d splitLine = new Line2d(pt, extents, dir); // push this line right or left or up or down based on ratio if (dir == 0) { splitLine = LineUtility.Move(splitLine, 0, orient * distance); } else { splitLine = LineUtility.Move(splitLine, orient * distance, 0); } Dictionary <string, object> intersectionReturn = MakeIntersections(poly, splitLine, spacingProvided); List <Point2d> intersectedPoints = (List <Point2d>)intersectionReturn["IntersectedPoints"]; List <Polygon2d> splittedPoly = (List <Polygon2d>)intersectionReturn["PolyAfterSplit"]; List <Point2d> ptA = (List <Point2d>)intersectionReturn["PointASide"]; List <Point2d> ptB = (List <Point2d>)intersectionReturn["PointBSide"]; Polygon2d polyA = new Polygon2d(ptA, 0), polyB = new Polygon2d(ptB, 0); //List<Polygon2d> splittedPoly = new List<Polygon2d>(); //splittedPoly.Add(polyA); splittedPoly.Add(polyB); return(new Dictionary <string, object> { { "PolyAfterSplit", (splittedPoly) }, { "SplitLine", (splitLine) }, { "IntersectedPoints", (intersectedPoints) }, { "PointASide", (ptA) }, { "PointBSide", (ptB) } }); }
//returns the points on the required side of a given line, 0 is left or up, 1 is right or down internal static List <Point2d> PointOnSide(Line2d line, List <Point2d> ptList, int side) { if (line == null || !ValidateObject.CheckPointList(ptList)) { return(null); } List <Point2d> selectedPts = new List <Point2d>(); if (side == 0) { } return(selectedPts); }
//returns the point having lowest x,y value from a list using now internal static int LowestPointFromList(List <Point2d> ptList) { if (!ValidateObject.CheckPointList(ptList)) { return(-1); } Point2d lowestPoint = ptList[0]; int size = ptList.Count; int index = 0; for (int i = 0; i < size; i++) { if ((lowestPoint.X > ptList[i].X) || (lowestPoint.X == ptList[i].X && lowestPoint.Y > ptList[i].Y)) { lowestPoint = ptList[i]; index = i; } } return(index); }
//returns the point having highest x,y value from a list - using now internal static int ReturnHighestPointFromList(List <Point2d> ptList) { if (!ValidateObject.CheckPointList(ptList)) { return(-1); } Point2d highestPoint = ptList[0]; int size = ptList.Count; int index = 0; for (int i = 0; i < size; i++) { if ((highestPoint.Y < ptList[i].Y) || (highestPoint.Y == ptList[i].Y && highestPoint.X > ptList[i].X)) { highestPoint = ptList[i]; index = i; } } return(index); }