示例#1
0
        public cyOXYCoordinate(cylineParam x, cylineParam y)
        {
            xline = x;
            yline = y;

            cyOXYLine.IntersectPoint(xline, yline, out orig);
        }
示例#2
0
        /// <summary>
        /// 根据拟合的两条直线,mainline ,coorline, 并取拟合coorline上某些点,做mainline的垂线,与coorline相交、
        /// 交点到直线mainline的距离, 根据【rows ,cols】的比例关系,换算成实际的距离尺寸,预期后期要做更改
        /// Date:2019 08 16
        /// </summary>
        /// <param name="mainline">基准线</param>
        /// <param name="coorline">测量线</param>
        /// <param name="measureRatio">图像方向上的坐标矩阵, 目前只用了x方向和y方向的,后期需要增加一些补偿因子等</param>
        /// <param name="xCoorPoint">拟合测量线用的点坐标 X, Image中的</param>
        /// <param name="yCoorPoint">拟合测量线用的点坐标 Y, Image中的</param>
        /// <param name="dist">计算得到的距离,后期看是算最大值还是最小值,还是平均值</param>
        /// <returns>当直线合理的时候,将返回true</returns>
        public static bool CalculateDistanceOfLine(ref cylineParam mainline, ref cylineParam coorline, double[] measureRatio, double[] xCoorPoint, double[] yCoorPoint, out float[] dist)
        {
            dist = new float[yCoorPoint.Length];
            if (xCoorPoint.Length != yCoorPoint.Length || xCoorPoint.Length <= 0)
            {
                return(false);
            }

            double div1 = coorline.B * mainline.B + coorline.A * mainline.A;

            for (int i = 0; i < xCoorPoint.Length; i++)
            {
                double c_justify = coorline.B * xCoorPoint[i] - coorline.A * yCoorPoint[i];
                double value1    = (mainline.B * (c_justify) + coorline.A * mainline.C) / div1;
                double value2    = (-mainline.A * c_justify + coorline.B * mainline.C) / div1;

                double r1 = coorline.A * measureRatio[0];
                double r2 = coorline.B * measureRatio[1];
                //double ratio = Math.Sqrt((r1 * r1 + r2 * r2) / 2);
                //这个比例系数需要修正,但哪种修正方式合适,目前还没有想出合理的方式,
                //double ratio = r1;
                double ratio = measureRatio[0];
                double dist1 = coorline.A * value1 + coorline.B * value2 - coorline.C;
                dist[i] = (float)(Math.Abs(dist1) * ratio);
            }
            return(true);
        }
示例#3
0
        public void SetCoordinateImageOrig(cyPoint2d orgPoint)
        {
            cylineParam line1 = xline;

            line1.C = xline.A * orgPoint.x + xline.B * orgPoint.y;
            xline   = line1;
            line1   = yline;
            line1.C = yline.A * orgPoint.x + yline.B * orgPoint.y;
            yline   = line1;

            orig = orgPoint;
        }
示例#4
0
        public cylineParam OnYPosLine(double yBias)
        {
            cyPoint2d localPoint;

            OnCoordinatePoint2Image(new cyPoint2d()
            {
                y = yBias, x = 0
            }, out localPoint);
            cylineParam line = xline;

            line.C = line.A * localPoint.x + line.B * localPoint.y;
            return(line);
        }
示例#5
0
        public cylineParam OnXPosLine(double xBias)
        {
            //做一条x = A的直线
            cyPoint2d localPoint;

            OnCoordinatePoint2Image(new cyPoint2d()
            {
                x = xBias, y = 0
            }, out localPoint);
            cylineParam line = yline;

            line.C = line.A * localPoint.x + line.B * localPoint.y;
            return(line);
        }
示例#6
0
        //根据x方向和y方向的比例关系,换算出新的坐标系关系
        public cyOXYCoordinate OnRatioCoordinate(double xRatio, double yRation)
        {
            cylineParam newXline = new cylineParam()
            {
                A = 0, B = 0, C = 0
            };
            cylineParam newYline = new cylineParam()
            {
                A = 0, B = 0, C = 0
            };

            newXline.A = xline.A * xRatio; newXline.B = xline.B * yRation; newXline.C = xline.C;
            newYline.A = yline.A * xRatio; newYline.B = yline.B * yRation; newYline.C = yline.C;
            double sqrt1 = 1 / Math.Sqrt(newXline.A * newXline.A + newXline.B * newXline.B);

            newXline = newXline * sqrt1;
            sqrt1    = 1 / Math.Sqrt(newYline.A * newYline.A + newYline.B * newYline.B);
            newYline = newYline * sqrt1;
            return(new cyOXYCoordinate(newXline, newYline));
        }
示例#7
0
        /// <summary>
        /// 将坐标的原点,移动到相对应的点上,作为原点。
        /// 也就是将坐标系中的点(x,y) 移动到 (0,0), 也就是 两条直线的交点处。
        /// </summary>
        /// <param name="coorlocalPoint"></param>
        public void SetCoordinateRelativateOrig(cyPoint2d PointValue)
        {
            cyPoint2d imgPoint1;

            OnCoordinatePoint2Image(PointValue, out imgPoint1);
            List <double> matrix = new List <double>(4)
            {
                xline.A, xline.B, yline.A, yline.B
            };
            List <double> outResult;

            Matrix_Mult2X1(matrix, imgPoint1.ToList(), out outResult);
            xline = new cylineParam()
            {
                A = xline.A, B = xline.B, C = outResult[0]
            };
            yline = new cylineParam()
            {
                A = yline.A, B = yline.B, C = outResult[1]
            };
            cyOXYLine.IntersectPoint(xline, yline, out orig);
        }
示例#8
0
        public static void IxLine2WxLine(cylineParam IxLine, out cylineParam Wxline, List <double> Rmatrix, List <double> offsetT)
        {
            /// Iz 用于补偿 图像中z的方向值
            Wxline = new cylineParam()
            {
                A = 0, B = 0, C = 0
            };
            List <double> RInvmatrix = new List <double>();

            MatrixInv3X3(Rmatrix, out RInvmatrix);
            if (RInvmatrix.Count != 9)
            {
                return;
            }

            Wxline.A = IxLine.A * RInvmatrix[0] + RInvmatrix[3] * IxLine.B;
            Wxline.B = IxLine.A * RInvmatrix[1] + RInvmatrix[4] * IxLine.B;
            double cAdd = Wxline.A * offsetT[0] + Wxline.B * offsetT[1];

            Wxline.C = cAdd + IxLine.C;
            double div = Math.Sqrt(Wxline.A * Wxline.A + Wxline.B * Wxline.B);

            Wxline.A /= div; Wxline.B /= div; Wxline.C /= div;
        }
示例#9
0
        /// <summary>
        /// 根据指定的点的图像中的坐标, 修正坐标直线的方向
        /// </summary>
        /// <param name="checkPoint">测试点</param>
        /// <param name="partIndex">测试点所在象限</param>
        public void OnMdodifyCoordilateXy(cyPoint2d checkPoint, int partIndex)
        {
            cyPoint2d coorPoint;

            OnPoint2Coordinate(checkPoint, out coorPoint);

            switch (partIndex)
            {
            case 1:    //(x > 0, y > 0 )
            {
                if (coorPoint.x < 0)
                {
                    yline = yline * (-1);
                }
                if (coorPoint.y < 0)
                {
                    xline = xline * (-1);
                }
                break;
            }

            case 2:    //(x < 0, y > 0)
            {
                //1,4
                if (coorPoint.x > 0)
                {
                    yline = yline * (-1);
                }
                if (coorPoint.y < 0)
                {
                    xline = xline * (-1);
                }
                break;
            }

            case 3:    //(x <0, y < 0)
            {
                if (coorPoint.x > 0)
                {
                    yline = yline * (-1);
                }
                if (coorPoint.y > 0)
                {
                    xline = xline * (-1);
                }
                break;
            }

            case 4:    //(x > 0, y < 0)
            {
                if (coorPoint.x < 0)
                {
                    yline = xline * (-1);
                }
                if (coorPoint.y > 0)
                {
                    xline = yline * (-1);
                }
                break;
            }

            default: break;
            }
            OnPoint2Coordinate(checkPoint, out coorPoint);
        }