Exemplo n.º 1
0
        public static double DistToPoint(this PointString poly, Vector p, int divs) // newly 20130523 近似法
        {
            var    points = poly.Points;
            double delta  = (double)(points.Count - 1) / divs;
            var    pts    = Enumerable.Range(0, divs + 1).Select(i => poly.Lerp(i * delta)).ToList();

            return(pts.Min(pt => pt.Dist(p)));
        }
Exemplo n.º 2
0
        public static PointString GetSubPoly(this PointString poly, double start, double end)
        {
            var points = poly.Points;

            start = (start < 0) ? 0 : start;
            end   = (end > points.Count - 1) ? (points.Count - 1) : end;
            var    pts = new List <Vector>();
            double a   = Math.Ceiling(start);
            double b   = Math.Floor(end);

            for (int i = (int)a; i <= (int)b; i++)
            {
                pts.Add(points[i]);
            }
            if (start < a)
            {
                pts.Insert(0, poly.Lerp(start));
            }
            if (end > b)
            {
                pts.Add(poly.Lerp(end));
            }
            return(new PointString(pts));
        }