Пример #1
0
        private static IEnumerable <Vector2> GetSegment(
            SequentialQuad <Vector2> points,
            float alpha,
            int splineResolution)
        {
            var result = new List <Vector2>();

            var t0 = 0.0f;
            var t1 = GetT(t0, points[0], points[1], alpha);
            var t2 = GetT(t1, points[1], points[2], alpha);
            var t3 = GetT(t2, points[2], points[3], alpha);

            for (var t = t1; t < t2; t += ((t2 - t1) / splineResolution))
            {
                Vector2 A1 = (t1 - t) / (t1 - t0) * points[0] + (t - t0) / (t1 - t0) * points[1];
                Vector2 A2 = (t2 - t) / (t2 - t1) * points[1] + (t - t1) / (t2 - t1) * points[2];
                Vector2 A3 = (t3 - t) / (t3 - t2) * points[2] + (t - t2) / (t3 - t2) * points[3];

                Vector2 B1 = (t2 - t) / (t2 - t0) * A1 + (t - t0) / (t2 - t0) * A2;
                Vector2 B2 = (t3 - t) / (t3 - t1) * A2 + (t - t1) / (t3 - t1) * A3;

                Vector2 C = (t2 - t) / (t2 - t1) * B1 + (t - t1) / (t2 - t1) * B2;

                result.Add(C);
            }

            return(result);
        }
Пример #2
0
        private static IEnumerable <Vector2> GetSegment(
            SequentialQuad <Vector2> points,
            float alpha,
            int resolution)
        {
            var segments = points.Pairwise();

            var t     = new SequentialQuad <float>(0f, 0f, 0f, 0f);
            var index = 0;

            foreach (var segment in segments)
            {
                t[index + 1] = GetT(t[index], segment, alpha);
                index++;
            }

            var center = t.Center;

            foreach (var x in center.LinearSpace(resolution))
            {
                var a1 =
                    (t[1] - x) / (t[1] - t[0]) * points[0]
                    + (x - t[0]) / (t[1] - t[0]) * points[1];

                var a2 =
                    (t[2] - x) / (t[2] - t[1]) * points[1]
                    + (x - t[1]) / (t[2] - t[1]) * points[2];

                var a3 =
                    (t[3] - x) / (t[3] - t[2]) * points[2]
                    + (x - t[2]) / (t[3] - t[2]) * points[3];


                var b1 =
                    (t[2] - x) / (t[2] - t[0]) * a1
                    + (x - t[0]) / (t[2] - t[0]) * a2;

                var b2 =
                    (t[3] - x) / (t[3] - t[1]) * a2
                    + (x - t[1]) / (t[3] - t[1]) * a3;


                yield return
                    ((t[2] - x) / (t[2] - t[1]) * b1
                     + (x - t[1]) / (t[2] - t[1]) * b2);
            }
        }
Пример #3
0
 public void Pair()
 {
     var s = new SequentialPair <int>(3, 5);
     var t = new SequentialTriple <int>(2, 6, 9);
     var o = new SequentialQuad <int>(6, 9, 10, 14);
 }