Esempio n. 1
0
        //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);
        }
Esempio n. 2
0
        //sorts list of points by distance from a given point
        public static List <Point2d> SortPointsByDistanceFromPoint(List <Point2d> ptList, Point2d testPoint)
        {
            List <Point2d> sortedPtList = new List <Point2d>();
            List <double>  distanceList = new List <double>();
            List <int>     indexList    = new List <int>();

            for (int i = 0; i < ptList.Count; i++)
            {
                distanceList.Add(PointUtility.DistanceBetweenPoints(ptList[i], testPoint));
            }
            indexList = BasicUtility.SortIndex(distanceList);
            for (int i = 0; i < indexList.Count; i++)
            {
                sortedPtList.Add(ptList[indexList[i]]);
            }
            return(sortedPtList);
        }