Exemple #1
0
        /// <summary>
        /// Splits the bezier at t and returns the two curves.
        /// </summary>
        /// <param name="t">Position to split (0 to 1).</param>
        /// <param name="b0">The curve from 0 to t.</param>
        /// <param name="b1">The curve from t to 1.</param>
        public void Split(float t, out Bezier2 b0, out Bezier2 b1)
        {
            int count = Control.Length;

            Vector2[] Q = new Vector2[count];
            Array.Copy(Control, Q, count);

            b0 = new Bezier2(Degree);
            b1 = new Bezier2(Degree);

            b0.Control[0]         = Control[0];
            b1.Control[count - 1] = Control[count - 1];

            for (int k = 1; k < count; k++)
            {
                int len = count - k;
                for (int i = 0; i < len; i++)
                {
                    Q[i] = (1.0f - t) * Q[i] + t * Q[i + 1];
                }

                b0.Control[k]       = Q[0];
                b1.Control[len - 1] = Q[len - 1];
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates a line with points more densely spaced at sharp curves.
        /// </summary>
        private Line2 CreateFromBezier(Bezier2 bezier, float spacing)
        {
            float length = bezier.Length(64);
            int   count  = (int)Mathf.Max(2, (length / spacing));

            Line2 line = new Line2();

            line.Control.AddRange(bezier.Control);

            for (int i = 0; i < count; i++)
            {
                float t = i / (count - 1.0f);
                line.Positions.Add(bezier.Position(t));
            }

            return(line);
        }
Exemple #3
0
        protected override void OnCurveComplete(List <Vector2> control)
        {
            Line2 line;

            if (Parametric)
            {
                ParametricBezier2 curve = new ParametricBezier2(control);
                line = CreateFromParametricBezier(curve, 0.1f);
            }
            else
            {
                Bezier2 curve = new Bezier2(control);
                line = CreateFromBezier(curve, 0.1f);
            }

            lines.Add(line);

            ResetInput();
        }