Beispiel #1
0
        public Cubic1D(float2[] data)
        {
            // Sort points to go strictly from left to right.
            List<float2> DataList = data.ToList();
            DataList.Sort((p1, p2) => p1.X.CompareTo(p2.X));
            data = DataList.ToArray();

            Data = data;
            Breaks = data.Select(i => i.X).ToArray();
            Coefficients = new float4[data.Length - 1];

            float[] h = MathHelper.Diff(data.Select(i => i.X).ToArray());
            float[] del = MathHelper.Div(MathHelper.Diff(data.Select(i => i.Y).ToArray()), h);
            float[] slopes = GetPCHIPSlopes(data, del);

            float[] dzzdx = new float[del.Length];
            for (int i = 0; i < dzzdx.Length; i++)
                dzzdx[i] = (del[i] - slopes[i]) / h[i];

            float[] dzdxdx = new float[del.Length];
            for (int i = 0; i < dzdxdx.Length; i++)
                dzdxdx[i] = (slopes[i + 1] - del[i]) / h[i];

            for (int i = 0; i < Coefficients.Length; i++)
                Coefficients[i] = new float4((dzdxdx[i] - dzzdx[i]) / h[i],
                                             2f * dzzdx[i] - dzdxdx[i],
                                             slopes[i],
                                             data[i].Y);
        }
Beispiel #2
0
        public Cubic1D2(float2[] data)
        {
            Data = data;
            Breaks = new[] { data[0].X, data[1].X };

            Coefficients = new float4[1];

            float h = data[1].X - data[0].X;
            float del = (data[1].Y - data[0].Y) / h;
            float[] slopes = { del, del };

            float[] dzzdx = new float[1];
            for (int i = 0; i < 1; i++)
                dzzdx[i] = (del - slopes[i]) / h;

            float[] dzdxdx = new float[1];
            for (int i = 0; i < 1; i++)
                dzdxdx[i] = (slopes[i + 1] - del) / h;

            for (int i = 0; i < 1; i++)
                Coefficients[i] = new float4((dzdxdx[i] - dzzdx[i]) / h,
                                             2f * dzzdx[i] - dzdxdx[i],
                                             slopes[i],
                                             data[i].Y);
        }
Beispiel #3
0
        public Cubic1D3(float2[] data)
        {
            Data = data;
            Breaks = new[] { data[0].X, data[1].X, data[2].X };

            Coefficients = new float4[2];

            float[] h = { data[1].X - data[0].X, data[2].X - data[1].X };
            float[] del = { (data[1].Y - data[0].Y) / h[0], (data[2].Y - data[1].Y) / h[1] };
            float[] slopes = GetPCHIPSlopes(data, del);

            float[] dzzdx = new float[2];
            for (int i = 0; i < 2; i++)
                dzzdx[i] = (del[i] - slopes[i]) / h[i];

            float[] dzdxdx = new float[2];
            for (int i = 0; i < 2; i++)
                dzdxdx[i] = (slopes[i + 1] - del[i]) / h[i];

            for (int i = 0; i < 2; i++)
                Coefficients[i] = new float4((dzdxdx[i] - dzzdx[i]) / h[i],
                                             2f * dzzdx[i] - dzdxdx[i],
                                             slopes[i],
                                             data[i].Y);
        }