Esempio n. 1
0
        public float BezierLength(List <Point2> Pts, float prec = 0.01f)
        {
            float sum = 0;

            for (float f = 0; f < 1f; f += prec)
            {
                Point2 a        = BezierInterpolate(Pts, f);
                Point2 b        = BezierInterpolate(Pts, f + prec);
                float  distance = (float)Math.Sqrt(Math.Pow(b.X - a.X, 2) + Math.Pow(b.Y - a.Y, 2));
                if (this.PixelLength > 0 && distance + sum <= this.PixelLength)
                {
                    DistanceTime dt = new DistanceTime();
                    sum        += distance;
                    dt.distance = sum;
                    dt.t        = f;
                    dt.point    = b;
                    this.distanceTime.Add(dt);
                }
                else
                {
                    break;
                }
            }
            return(sum);
        }
Esempio n. 2
0
        public Point2 UniformSpeed(List <Point2> points, float target)
        {
            int high = this.distanceTime.Count - 1;
            int low  = 0;

            while (low <= high)
            {
                int mid = (high + low) / 2;
                if (mid == high || mid == low)
                {
                    if (mid + 1 >= this.distanceTime.Count)
                    {
                        return(this.distanceTime[mid].point);
                    }
                    else
                    {
                        DistanceTime a = this.distanceTime[mid];
                        DistanceTime b = this.distanceTime[mid + 1];
                        return(a.point.Lerp(b.point, (target - a.distance) / (b.distance - a.distance)));
                    }
                }
                if (this.distanceTime[mid].distance > target)
                {
                    high = mid;
                }
                else
                {
                    low = mid;
                }
            }
            return(new Point2());
        }
Esempio n. 3
0
            public float Length(float prec = 0.01f)
            {
                float sum = 0;

                for (float f = 0; f < 1f; f += prec)
                {
                    Point2       a        = Interpolate(f);
                    Point2       b        = Interpolate(f + prec);
                    float        distance = (float)Math.Sqrt(Math.Pow(b.X - a.X, 2) + Math.Pow(b.Y - a.Y, 2));
                    DistanceTime dt       = new DistanceTime();
                    sum        += distance;
                    dt.distance = sum;
                    dt.t        = f;
                    dt.point    = b;
                    this.parent.distanceTime.Add(dt);
                }
                return(sum);
            }