Beispiel #1
0
        public static cylineParam OnGetLine(cyPoint2d point1, cyPoint2d point2)
        {
            cylineParam line1 = new cylineParam();

            line1.A = point1.y - point2.y;
            line1.B = -(point1.x - point2.x);
            line1.C = line1.A * point1.x + line1.B * point1.y;
            line1.OnNormalize();
            return(line1);
        }
Beispiel #2
0
        public static bool leastSquareAdaptLineWeight(List <double> xArray, List <double> yArray, List <double> weight, out cylineParam lineValue)
        {
            Trace.Assert(xArray.Count == yArray.Count);
            cyPointBaseClass class1 = new cyPointBaseClass();

            lineValue = new cylineParam()
            {
                A = 0, B = 0, C = 0
            };

            int           nums   = xArray.Count;
            List <double> matrix = new List <double>()
            {
                0, 0, 0, 0
            };
            List <double> bias = new List <double>()
            {
                0, 0
            };
            double xx = 0, xy = 0, yy = 0, x = 0, y = 0;

            for (int i = 0; i < xArray.Count; i++)
            {
                xx += xArray[i] * xArray[i] * weight[i];
                yy += yArray[i] * yArray[i] * weight[i];
                xy += xArray[i] * yArray[i] * weight[i];
                x  += xArray[i] * weight[i];
                y  += yArray[i] * weight[i];
            }

            matrix[0] = xx; matrix[1] = xy;
            matrix[2] = matrix[1]; matrix[3] = yy;
            bias[0]   = x; bias[1] = y;
            List <double> result;
            List <double> invMatrix;

            cyUCSMeasure.MatrixInv2X2(matrix, out invMatrix);
            cyUCSMeasure.Matrix_Mult2X1(invMatrix, bias, out result);
            lineValue.A = result[0]; lineValue.B = result[1];
            //double c = (result[0]*x + result[1]*y) /weight.Sum() ;
            lineValue = new cylineParam()
            {
                A = result[0], B = result[1], C = 1
            };
            lineValue.OnNormalize();
            return(true);
        }