コード例 #1
0
        /// <summary>
        /// Implementation of the Ramer–Douglas–Peucker algorithm, which consist for reducing the nomber of usefull point for creating a line;
        /// en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
        /// </summary>
        /// <param name="list_of_points"></param>
        /// <param name="epsilon"></param>
        public static List <PolarPointRssiExtended> IEPF_Algorithm(List <PolarPointRssiExtended> list_of_points, double epsilon)
        {
            double dmax  = 0;
            int    index = 0;
            int    end   = list_of_points.Count();

            PointDExtended first_point = Toolbox.ConvertPolarToPointD(list_of_points[0]);
            PointDExtended end_point   = Toolbox.ConvertPolarToPointD(list_of_points[end - 1]);
            double         angle       = Math.Atan2(first_point.Pt.Y - end_point.Pt.Y, first_point.Pt.X - end_point.Pt.X);

            for (int i = 1; i < end - 1; i++)
            {
                double distance = Toolbox.DistancePointToLine(Toolbox.ConvertPolarToPointD(list_of_points[i]).Pt, first_point.Pt, angle);
                if (distance > dmax)
                {
                    index = i;
                    dmax  = distance;
                }
            }

            List <PolarPointRssiExtended> ResultList = new List <PolarPointRssiExtended>();

            /// If max dist is greater than epsilon -> Recursively Simplify
            if (dmax > epsilon)
            {
                List <PolarPointRssiExtended> recursiveResult1 = IEPF_Algorithm(list_of_points.GetRange(0, index), epsilon);
                List <PolarPointRssiExtended> recursiveResult2 = IEPF_Algorithm(list_of_points.GetRange(index + 1, end - 1 - index), epsilon);

                ResultList.AddRange(recursiveResult1);
                ResultList.AddRange(recursiveResult2);
            }
            else
            {
                ResultList.Add(list_of_points[0]);
                ResultList.Add(list_of_points[end - 1]);
            }
            return(ResultList);
        }
コード例 #2
0
 public void AddPtExtended(PointDExtended pt)
 {
     ptList.Add(pt);
 }