public static CubicBezier2D[] Split1(double aX, double aY, double bX, double bY, double cX, double cY, double dX, double dY, params double[] ts)
        {
            if (ts is null)
            {
                return(new[] { new CubicBezier2D(aX, aY, bX, bY, cX, cY, dX, dY) });
            }

            var filtered = ts.Where(t => t >= 0d && t <= 1d).Distinct().OrderBy(t => t).ToList();
            var prev     = new CubicBezier2D(aX, aY, bX, bY, cX, cY, dX, dY);

            if (filtered.Count == 0)
            {
                return(new[] { prev });
            }

            var tLast = 0d;
            var list  = new List <CubicBezier2D>(filtered.Count + 1);

            foreach (var t in filtered)
            {
                var relT = (1d - t) / (1d - tLast);
                tLast     = t;
                var(A, B) = BisectCubicBezierTests.BisectCubicBezier(prev.A.X, prev.A.Y, prev.B.X, prev.B.Y, prev.C.X, prev.C.Y, prev.D.X, prev.D.Y, relT);
                list.Add(A);
                prev = B;
            }

            list.Add(prev);
            return(list.ToArray());
        }
Пример #2
0
        /// <summary>
        /// The interpolate points.
        /// </summary>
        /// <param name="bezier">The bezier.</param>
        /// <param name="count">The count.</param>
        /// <returns>The <see cref="List{Point2D}"/>.</returns>
        public static List <Point2D> InterpolatePoints(CubicBezier2D bezier, int count)
        {
            var ipoints = new Point2D[count + 1];

            for (var i = 0; i <= count; i += 1)
            {
                var v = 1d / count * i;
                ipoints[i] = bezier.Interpolate(v);
            }

            return(new List <Point2D>(ipoints));
        }
Пример #3
0
 /// <summary>
 /// The interpolate cubic beizer points.
 /// </summary>
 /// <param name="bezier">The bezier.</param>
 /// <param name="count">The count.</param>
 /// <returns>The <see cref="List{Point2D}"/>.</returns>
 public static List <Point2D> InterpolateCubicBeizerPoints(CubicBezier2D bezier, int count)
 => InterpolateCubicBeizerPoints(bezier.A, bezier.B, bezier.C, bezier.D, count);