示例#1
0
        //計算向量
        public Tuple <Data.VecInfo> XYVector(DataTable data)
        {
            double[] vec = new double[num]; //創建一個陣列存放向量

            int clockwise        = 0;       //順時針
            int counterclockwise = 0;       //逆時針

            for (int i = 0; i < num - 1; i++)
            {
                var X1 = Convert.ToInt32(data.Rows[i + 1]["X"]) - Convert.ToInt32(data.Rows[i]["X"]);
                var X2 = Convert.ToInt32(data.Rows[i + 2]["X"]) - Convert.ToInt32(data.Rows[i + 1]["X"]);
                var Y1 = Convert.ToInt32(data.Rows[i + 1]["Y"]) - Convert.ToInt32(data.Rows[i]["Y"]);
                var Y2 = Convert.ToInt32(data.Rows[i + 2]["Y"]) - Convert.ToInt32(data.Rows[i + 1]["Y"]);
                vec[i] = X1 * Y2 - Y1 * X2;

                if (vec[i] > 0)
                {
                    counterclockwise++;
                }
                else if (vec[i] < 0)
                {
                    clockwise++;
                }
            }
            Data.VecInfo vecInfo = new Data.VecInfo
            {
                clockwise        = clockwise,
                counterclockwise = counterclockwise,
            };
            return(new Tuple <Data.VecInfo>(vecInfo));
        }
示例#2
0
        //計算向量
        public Tuple <Data.VecInfo> XYVector(List <Data.Coordinates> data, int userSelectID, int show_num, int start_num)
        {
            double[] vec              = new double[count]; //創建一個陣列存放向量
            int      clockwise        = 0;                 //順時針
            int      counterclockwise = 0;                 //逆時針

            SelectXAxis(data, userSelectID);
            SelectYAxis(data, userSelectID);

            if (show_num == count && start_num == 0)    //只做到篩選ID,顯示全部資料,初始值為第一筆開始
            {
                for (int i = 0; i < count - 3; i++)
                {
                    var X1 = x[i + 1] - x[i];
                    var X2 = x[i + 2] - x[i];
                    var Y1 = y[i + 1] - y[i];
                    var Y2 = y[i + 2] - y[i];
                    vec[i] = X1 * Y2 - Y1 * X2;

                    if (vec[i] > 0)
                    {
                        counterclockwise++;
                    }
                    else if (vec[i] < 0)
                    {
                        clockwise++;
                    }
                }
            }
            else if (show_num != 0 && start_num == 0)     //顯示筆數不為0,起始值為初始
            {
                for (int i = 0; i < show_num - 3; i++)
                {
                    var X1 = x[i + 1] - x[i];
                    var X2 = x[i + 2] - x[i];
                    var Y1 = y[i + 1] - y[i];
                    var Y2 = y[i + 2] - y[i];
                    vec[i] = X1 * Y2 - Y1 * X2;

                    if (vec[i] > 0)
                    {
                        counterclockwise++;
                    }
                    else if (vec[i] < 0)
                    {
                        clockwise++;
                    }
                }
            }
            else if (show_num == 0)     //無限制顯示筆數
            {
                for (int i = 0; i < count - 3; i++)
                {
                    var X1 = x[i + 1] - x[i];
                    var X2 = x[i + 2] - x[i];
                    var Y1 = y[i + 1] - y[i];
                    var Y2 = y[i + 2] - y[i];
                    vec[i] = X1 * Y2 - Y1 * X2;

                    if (vec[i] > 0)
                    {
                        counterclockwise++;
                    }
                    else if (vec[i] < 0)
                    {
                        clockwise++;
                    }
                }
            }
            else if (show_num != 0 && start_num != 0)       //顯示筆數不為0,起始不為初始值
            {
                if (start_num + show_num - 1 <= count)      //在資料筆數內
                {
                    for (int i = start_num - 1; i < start_num + show_num - 3; i++)
                    {
                        var X1 = x[i + 1] - x[i];
                        var X2 = x[i + 2] - x[i];
                        var Y1 = y[i + 1] - y[i];
                        var Y2 = y[i + 2] - y[i];
                        vec[i] = X1 * Y2 - Y1 * X2;

                        if (vec[i] > 0)
                        {
                            counterclockwise++;
                        }
                        else if (vec[i] < 0)
                        {
                            clockwise++;
                        }
                    }
                }
                else       //在資料筆數外
                {
                    for (int i = start_num - 1; i < count - 3; i++)
                    {
                        var X1 = x[i + 1] - x[i];
                        var X2 = x[i + 2] - x[i];
                        var Y1 = y[i + 1] - y[i];
                        var Y2 = y[i + 2] - y[i];
                        vec[i] = X1 * Y2 - Y1 * X2;

                        if (vec[i] > 0)
                        {
                            counterclockwise++;
                        }
                        else if (vec[i] < 0)
                        {
                            clockwise++;
                        }
                    }
                }
            }
            else if (show_num == 0 && start_num != 0)      //無限制筆數,限制起始值
            {
                for (int i = start_num - 1; i < count - 3; i++)
                {
                    var X1 = x[i + 1] - x[i];
                    var X2 = x[i + 2] - x[i];
                    var Y1 = y[i + 1] - y[i];
                    var Y2 = y[i + 2] - y[i];
                    vec[i] = X1 * Y2 - Y1 * X2;

                    if (vec[i] > 0)
                    {
                        counterclockwise++;
                    }
                    else if (vec[i] < 0)
                    {
                        clockwise++;
                    }
                }
            }

            Data.VecInfo vecInfo = new Data.VecInfo
            {
                clockwise        = clockwise,
                counterclockwise = counterclockwise,
            };
            return(new Tuple <Data.VecInfo>(vecInfo));
        }