Пример #1
0
        /// <summary>
        /// 双线性插值
        /// p00 ------------- p01
        ///  |                 |
        /// p10 ------------- p11
        ///
        /// TODO: handle boundary.
        /// </summary>
        /// <param name="f">二维图</param>
        /// <param name="x">x</param>
        /// <param name="y">y</param>
        /// <param name="method"></param>
        /// <returns></returns>
        public static NcvVector interp2(double[] f, int cols, int rows, NcvVector x, NcvVector y, string method)
        {
            int       n  = x.n;
            NcvVector vf = new NcvVector(n);

            if (method.Equals("*linear", StringComparison.OrdinalIgnoreCase))
            {
                for (int k = 0; k < n; k++)
                {
                    int p00Y = (int)Math.Floor(y[k]);
                    int p00X = (int)Math.Floor(x[k]);
                    int p01Y = (int)Math.Floor(y[k]);
                    int p01X = (int)Math.Ceiling(x[k]);
                    int p10Y = (int)Math.Ceiling(y[k]);
                    int p10X = (int)Math.Floor(x[k]);
                    int p11Y = (int)Math.Ceiling(y[k]);
                    int p11X = (int)Math.Ceiling(x[k]);

                    double a   = y[k] - p00Y;
                    double b   = x[k] - p00X;
                    double f00 = f[p00X * rows + p00Y];
                    double f01 = f[p01X * rows + p01Y];
                    double f10 = f[p10X * rows + p10Y];
                    double f11 = f[p11X * rows + p11Y];
                    double g   = b * (a * f11 + (1 - a) * f01) + (1 - b) * (a * f01 + (1 - a) * f00);

                    //int i = round(x[k]) * m_Rows + round(y[k]);
                    vf[k] = g;
                }
            }
            return(vf);
        }
Пример #2
0
        public static void DrawContour(Bitmap bmp, NcvVector x, NcvVector y)
        {
            List <DoublePoint> contour = new List <DoublePoint>();

            for (int i = 0; i < x.n; i++)
            {
                contour.Add(new DoublePoint(x[i], y[i]));
            }
            DrawContour(bmp, contour);
        }
Пример #3
0
        public static NcvVector DotProduct(NcvVector v1, NcvVector v2)
        {
            NcvVector v3 = new NcvVector(v1.n);

            for (int i = 0; i < v1.n; i++)
            {
                v3[i] = v1[i] * v2[i];
            }
            return(v3);
        }
Пример #4
0
        public static NcvVector operator *(NcvVector v1, double s2)
        {
            NcvVector v3 = new NcvVector(v1.n);

            for (int i = 0; i < v1.n; i++)
            {
                v3[i] = v1[i] * s2;
            }
            return(v3);
        }
Пример #5
0
        public static NcvVector operator -(NcvVector v1)
        {
            NcvVector v2 = new NcvVector(v1.n);

            for (int i = 0; i < v1.n; i++)
            {
                v2[i] = -v1[i];
            }
            return(v2);
        }
Пример #6
0
        public static NcvVector Ones(int n)
        {
            NcvVector ones = new NcvVector(n);

            for (int i = 0; i < ones.n; i++)
            {
                ones[i] = 1.0;
            }
            return(ones);
        }
Пример #7
0
        public static NcvVector Sqrt(NcvVector v1)
        {
            NcvVector v2 = new NcvVector(v1.n);

            for (int i = 0; i < v1.n; i++)
            {
                v2[i] = Math.Sqrt(v1[i]);
            }
            return(v2);
        }
Пример #8
0
        public static NcvMatrix diag(NcvVector v)
        {
            int       n = v.n;
            NcvMatrix m = new NcvMatrix(n, n);

            for (int i = 0; i < n; i++)
            {
                m[i, i] = v[i];
            }
            return(m);
        }
Пример #9
0
        public static NcvVector operator -(NcvVector v1, NcvVector v2)
        {
            NcvVector v3 = new NcvVector(v1.n);

            // v3 <- v1 + v2
            for (int i = 0; i < v1.n; i++)
            {
                v3[i] = v1[i] - v2[i];
            }
            return(v3);
        }
Пример #10
0
        public static NcvVector operator *(NcvMatrix m1, NcvVector v2)
        {
            NcvVector v3 = new NcvVector(v2.n);

            for (int y = 0; y < m1.rows(); y++)
            {
                for (int x = 0; x < m1.cols(); x++)
                {
                    v3[y] += m1[x, y] * v2[y];
                }
            }

            return(v3);
        }
Пример #11
0
        public static NcvVector cat(NcvVector v1, NcvVector v2)
        {
            NcvVector v3 = new NcvVector(v1.n + v2.n);

            for (int i = 0; i < v1.n; i++)
            {
                v3[i] = v1[i];
            }
            for (int j = 0; j < v2.n; j++)
            {
                v3[v1.n + j] = v2[j];
            }
            return(v3);
        }
Пример #12
0
        public NcvVector sub(int startIndex, int length)
        {
            if (startIndex + length > this.n)
            {
                throw new ArgumentOutOfRangeException();
            }

            NcvVector v = new NcvVector(length);

            for (int i = 0; i < length; i++)
            {
                v[i] = this[startIndex + i];
            }
            return(v);
        }
Пример #13
0
        public static NcvMatrix diag(NcvVector v, int k)
        {
            int n     = v.n;
            int order = n + Math.Abs(k);

            NcvMatrix m = new NcvMatrix(order, order);

            for (int i = 0; i < n; i++)
            {
                if (k <= 0)
                {
                    m[i, i - k] = v[i];
                }
                else
                {
                    m[i + k, i] = v[i];
                }
            }
            return(m);
        }
Пример #14
0
 public static NcvVector interp1(NcvVector x, NcvVector Y, NcvVector xi)
 {
     return(new NcvVector(interp1(x.Data, Y.Data, xi.Data)));
 }