public void Spline()
        {
            int n = 6;

            // Create the data to be fitted
            float[] x    = new float[n];
            float[] y    = new float[n];
            var     rand = new Random(1);

            for (int i = 0; i < n; i++)
            {
                x[i] = i;
                y[i] = (float)rand.NextDouble() * 10;
            }

            // Compute the x values at which we will evaluate the spline.
            // Upsample the original data by a const factor.
            int upsampleFactor = 10;
            int nInterpolated  = n * upsampleFactor;

            float[] xs = new float[nInterpolated];

            for (int i = 0; i < nInterpolated; i++)
            {
                xs[i] = (float)i * (n - 1) / (float)(nInterpolated - 1);
            }

            float[] ys = CubicSpline.Compute(x, y, xs, 0.0f, Single.NaN, true);

            Assert.True(xs.Length == 60 && ys.Length == 60);
        }
Exemple #2
0
    bool UpdateSpline()
    {
        int n_knot = m_knots.Length;

        if (n_knot > 3)
        {
            float[] i_knot = new float[n_knot];
            float[] x_knot = new float[n_knot];
            float[] y_knot = new float[n_knot];
            float[] z_knot = new float[n_knot];
            m_pknotsM = new Vector3[n_knot];
            for (int i = 0; i < n_knot; i++)
            {
                m_pknotsM[i] = m_knots[i].transform.position;
                i_knot[i]    = i;
                x_knot[i]    = m_pknotsM[i].x;
                y_knot[i]    = m_pknotsM[i].y;
                z_knot[i]    = m_pknotsM[i].z;
            }

            float[] i_ierps   = new float[m_nIerps];
            float   ierp_step = (float)(n_knot - 1) / (float)(m_nIerps - 1);
            i_ierps[0] = 0;
            for (int i = 1; i < m_nIerps; i++)
            {
                i_ierps[i] = i_ierps[i - 1] + ierp_step;
            }
            float[] x_ierps = CubicSpline.Compute(i_knot, x_knot, i_ierps);
            float[] y_ierps = CubicSpline.Compute(i_knot, y_knot, i_ierps);
            float[] z_ierps = CubicSpline.Compute(i_knot, z_knot, i_ierps);

            m_pIerps = new Vector3[m_nIerps];
            for (int i = 0; i < m_nIerps; i++)
            {
                m_pIerps[i].x = x_ierps[i];
                m_pIerps[i].y = y_ierps[i];
                m_pIerps[i].z = z_ierps[i];
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemple #3
0
        public static int GetPitchTime(MainForm mainForm,
                                       string droneName,
                                       int power,
                                       double meter)
        {
            CalibrationInfo     cInfo  = CalibrationList.GetCalibrationData(mainForm, droneName);
            MoveCalibrationInfo mcInfo = cInfo.GetMoveInfo(power);

            if (mcInfo == null)
            {
                mainForm.ShowMessageBox("Power " + power + " data doesn't exist.");
                return(-1);
            }

            float[] times  = Array.ConvertAll(mcInfo.GetTimes(), x => (float)x); // x
            float[] meters = new float[times.Length];                            // y
            for (int i = 0; i < meters.Length; i++)
            {
                if (power > 0)
                {
                    meters[i] = (float)mcInfo.GetFrontMeter((int)times[i]);
                }
                else
                {
                    meters[i] = (float)mcInfo.GetBackMeter((int)times[i]);
                }
            }

            if (meters.Min() > meter || meters.Max() < meter)
            {
                mainForm.ShowMessageBox("Meter " + meter + " is out of data range.");
                return(-1);
            }

            float[] timeResult = CubicSpline.Compute(meters, times, new float[] { (float)meter });
            return((int)timeResult[0]);
        }