コード例 #1
0
        public static void FitParametric(float[] x, float[] y, int nOutputPoints, out float[] xs, out float[] ys,
                                         float firstDx = NaN, float firstDy = NaN, float lastDx = NaN, float lastDy = NaN)
        {
            int n = x.Length;

            float[] dists = new float[n];
            dists[0] = 0;
            float totalDist = 0;

            for (int i = 1; i < n; i++)
            {
                float dx   = x[i] - x[i - 1];
                float dy   = y[i] - y[i - 1];
                float dist = (float)Math.Sqrt(dx * dx + dy * dy);
                totalDist += dist;
                dists[i]   = totalDist;
            }

            float dt = totalDist / (nOutputPoints - 1);

            float[] times = new float[nOutputPoints];
            times[0] = 0;

            for (int i = 1; i < nOutputPoints; i++)
            {
                times[i] = times[i - 1] + dt;
            }

            NormalizeVector(ref firstDx, ref firstDy);
            NormalizeVector(ref lastDx, ref lastDy);

            CubicSpline xSpline = new CubicSpline();

            xs = xSpline.FitAndEval(dists, x, times, firstDx / dt, lastDx / dt);

            CubicSpline ySpline = new CubicSpline();

            ys = ySpline.FitAndEval(dists, y, times, firstDy / dt, lastDy / dt);
        }
コード例 #2
0
        public static float[] Compute(float[] x, float[] y, float[] xs, float startSlope = NaN, float endSlope = NaN, bool debug = false)
        {
            CubicSpline spline = new CubicSpline();

            return(spline.FitAndEval(x, y, xs, startSlope, endSlope, debug));
        }