Пример #1
0
        private void CalculateBezier()
        {
            Bezier.Clear();
            Tangents.Clear();
            GC.Collect();
            List <Point> points = new List <Point>();

            for (double i = 0d; i < 5000; i++)
            {
                double t = i / 5000d;
                double X = 0;
                double Y = 0;
                for (int c = 0; c < PointCount; c++)
                {
                    X += Algorithms.Binom(PointCount - 1, c) * Math.Pow(1d - t, PointCount - 1 - c) * Math.Pow(t, c) * (double)ControlPoints[c].X;
                    Y += Algorithms.Binom(PointCount - 1, c) * Math.Pow(1d - t, PointCount - 1 - c) * Math.Pow(t, c) * (double)ControlPoints[c].Y;
                }
                if (points.Count == 0 || points[points.Count - 1].X != (int)X || points[points.Count - 1].Y != (int)Y)
                {
                    points.Add(new Point((int)X, (int)Y));
                    X = 0;
                    Y = 0;
                    for (int c = 0; c < PointCount - 1; c++)
                    {
                        X += Algorithms.Binom(PointCount - 2, c) * Math.Pow(1d - t, PointCount - 2 - c) * Math.Pow(t, c) * (double)(ControlPoints[c + 1].X - ControlPoints[c].X) * (PointCount - 1);
                        Y += Algorithms.Binom(PointCount - 2, c) * Math.Pow(1d - t, PointCount - 2 - c) * Math.Pow(t, c) * (double)(ControlPoints[c + 1].Y - ControlPoints[c].Y) * (PointCount - 1);
                    }
                    Tangents.Add(new Vector2((float)X, (float)Y));
                }
            }
            Bezier       = points.ToList();
            currentPoint = Math.Min(Bezier.Count - 1, currentPoint);
        }
Пример #2
0
 public void ClearSegment()
 {
     if (UseBezier)
     {
         mBezier.Clear();
     }
     else
     {
         mSegment.Clear();
     }
 }