コード例 #1
0
        /// <summary>
        /// Creates a list of equally spaced points that lie on the path described by straight line segments between
        /// adjacent points in the source list.
        /// </summary>
        /// <param name="src">Source list of points.</param>
        /// <param name="md">Distance between points on the new path.</param>
        /// <returns>List of equally-spaced points on the path.</returns>
        public static List <VECTOR> Linearize(List <VECTOR> src, FLOAT md)
        {
            if (src == null)
            {
                throw new ArgumentNullException("src");
            }
            if (md <= VectorHelper.EPSILON)
            {
                throw new InvalidOperationException("md " + md + " is be less than epislon " + EPSILON);
            }
            List <VECTOR> dst = new List <VECTOR>();

            if (src.Count > 0)
            {
                VECTOR pp = src[0];
                dst.Add(pp);
                FLOAT cd = 0;
                for (int ip = 1; ip < src.Count; ip++)
                {
                    VECTOR p0 = src[ip - 1];
                    VECTOR p1 = src[ip];
                    FLOAT  td = VectorHelper.Distance(p0, p1);
                    if (cd + td > md)
                    {
                        FLOAT pd = md - cd;
                        dst.Add(VectorHelper.Lerp(p0, p1, pd / td));
                        FLOAT rd = td - pd;
                        while (rd > md)
                        {
                            rd -= md;
                            VECTOR np = VectorHelper.Lerp(p0, p1, (td - rd) / td);
                            if (!VectorHelper.EqualsOrClose(np, pp))
                            {
                                dst.Add(np);
                                pp = np;
                            }
                        }
                        cd = rd;
                    }
                    else
                    {
                        cd += td;
                    }
                }
                // last point
                VECTOR lp = src[src.Count - 1];
                if (!VectorHelper.EqualsOrClose(pp, lp))
                {
                    dst.Add(lp);
                }
            }
            return(dst);
        }