/// <summary> /// 此方法用来判断源矩形区域中是否包含目标矩形区域,即是否可以剪切 /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <returns></returns> public static bool canClip(Recatangle source, Recatangle target) { bool canClip = false; //首先判断两个矩形区域是否重合 if (isOverlap(source, target) && isSame(source, target))//首先判断两个矩形是否完全重合 { Console.WriteLine("两个图形完全重合了!!!可以剪切"); canClip = true; return(canClip); } //第1个矩形左上角的坐标 double ALX = source.P.X; double ALY = source.P.Y; //第1个矩形右下角的坐标 double ARX = ALX + source.Width; double ARY = ALY - source.Height; //第2个矩形左上角的坐标 double BLX = target.P.X; double BLY = target.P.Y; //第2个矩形右下角的坐标 double BRX = BLX + target.Width; double BRY = BLY - target.Height; double min1 = getMax(getMin(ALX, ARX), getMin(BLX, BRX)); double min2 = getMax(getMin(ALY, ARY), getMin(BLY, BRY)); double max1 = getMin(getMax(ALX, ARX), getMax(BLX, BRX)); double max2 = getMin(getMax(ALY, ARY), getMax(BLY, BRY)); Console.WriteLine("ALX={0},ALY={1},ARX={2},ARY={3}", ALX, ALY, ARX, ARY); Console.WriteLine("BLX={0},BLY={1},BRX={2},BRY={3}", BLX, BLY, BRX, BRY); Console.WriteLine("min1={0},min2={1},max1={2},max2={3}", min1, min2, max1, max2); Console.WriteLine("max1 - min1={0},max2 - min2={1},(max1 - min1) * (max2 - min2)={2}", max1 - min1, max2 - min2, (max1 - min1) * (max2 - min2)); if (min1 < max1 && max2 > min2) {//说明两个矩形相交 canClip = false; Console.WriteLine("两个矩形有交集!!!"); } else { //说明这两个矩形有相互包含的情况 if (source.Width * source.Height != target.Width * target.Height && (max1 - min1) * (max2 - min2) > 0) //说明recA包含recB { canClip = true; Console.WriteLine("两个矩形相互包含。"); } else { canClip = false; Console.WriteLine("两个矩形相离"); Console.WriteLine("出现异常,请检查输入参数是否正确。"); } } return(canClip); }
public static Recatangle Test() { Recatangle target = new Recatangle(new Point(0, 0), 0, 0); target = Image2UserCoordinateSystem(target); return(target); }
/// <summary> /// /// </summary> /// <param name="origion"></param> /// <param name="ctms"></param> /// <returns></returns> public static Recatangle setCTMTransform(Recatangle origion, List <Matrix> ctms) { Recatangle target = new Recatangle(new Point(0, 0), 0, 0); // Image2Pattern(origion, ctms, target); target = Plot2UserCoordinateSystem(origion, ctms, target); return(target); }
private static Recatangle BBOX2CoordinateSystem(Recatangle origion, List <Matrix> ctms, Recatangle target) { Console.WriteLine("**********BBOX2CoordinateSystem************"); double ALXO = origion.P.X; double ALYO = origion.P.Y; double ARXO = origion.P.X + origion.Width; double ARYO = origion.P.Y - origion.Height; Console.WriteLine("ALXO={0},ALYO={1},ARXO={2},ARYO={3}", ALXO, ALYO, ARXO, ARYO); double[][] points = new double[][] { new double[] { ALXO, ALYO, 1 }, //左上角的点 new double[] { ARXO, ARYO, 1 }, //右下角的点 }; double[][] results = new double[][] { new double[] { 0, 0, 1 }, //左上角的点 new double[] { 0, 0, 1 }, //右下角的点 }; Matrix ctm = null; double[][] _ctm = null; ctm = ctms[0]; _ctm = ctm.Points; Console.WriteLine("origion matrix"); Matrix.PrintMatrix(points); Console.WriteLine(); Console.WriteLine("CTM matrix"); Matrix.PrintMatrix(_ctm); Console.WriteLine(); results = Matrix.MatrixMult(points, _ctm); Console.WriteLine("result matrix"); Matrix.PrintMatrix(results); Console.WriteLine(); Console.WriteLine("********************"); points = results; //update the matrix //将计算出来的矩形区域的主对角线的两点分别给相应的(BLX,BLY)(BRX,BRY)赋值,并输出结果矩形 double BLX = points[0][0]; double BLY = points[0][1]; double BRX = points[1][0]; double BRY = points[1][1]; target.P.X = BLX; target.P.Y = BLY; target.Width = BRX - BLX; target.Height = BLY - BRY; return(target); }
public static Recatangle setCTMTransform(Recatangle origion, List <Matrix> ctms) { Recatangle target = new Recatangle(new Point(0, 0), 0, 0); // Image2Pattern(origion, ctms, target); //target = BBOX2CoordinateSystem(origion, ctms, target);//BBOX映射到用户坐标空间 // target=Image2UserCoordinateSystem(origion, ctms, target);//真正的图片一直映射到用户坐标空间。 target = Image2UserCoordinateSystem(target); // target = Plot2UserCoordinateSystem(origion, ctms, target); return(target); }
public static double[][] ConvertRect2Arr(Recatangle rect) { double rlx = rect.P.X; double rly = rect.P.Y; double rrx = rect.P.X + rect.Width; double rry = rect.P.Y - rect.Height; double[][] result = new double[][] { new double[] { rlx, rly, 1 }, new double[] { rrx, rry, 1 } }; return(result); }
public static bool isSame(Recatangle rc1, Recatangle rc2) { if (rc1.P.X == rc2.P.X && rc2.P.Y == rc1.P.Y && rc1.Height == rc2.Height && rc2.Width == rc1.Width ) { return(true);//isSame } else { return(false);//no overlap } }
/// <summary> /// 判断两个轴对齐的矩形是否重叠 /// </summary> /// <param name="rc1">第1个矩阵的位置</param> /// <param name="rc2">第2个矩阵的位置</param> /// <returns>两个矩阵是否重叠(边沿重叠,也认为是重叠)</returns> public static bool isOverlap(Recatangle rc1, Recatangle rc2) { if (rc1.P.X + rc1.Width > rc2.P.X && rc2.P.X + rc2.Width > rc1.P.X && rc1.P.Y + rc1.Height > rc2.P.Y && rc2.P.Y + rc2.Height > rc1.P.Y ) { return(true);//overlap } else { return(false);//no overlap } }
private static void Plot2UserCoordinateSystem() { Console.WriteLine(); Console.WriteLine("**********Plot2UserCoordinateSystem**************"); Recatangle rect = new Recatangle(new Point(73.79926, -87.735), 303.39074, 160.05); List <Matrix> ctms = new List <Matrix>(); double[][] p1 = new double[][] { new double[] { 4 / 3.0000, 0, 0 }, new double[] { 0, 4 / 3.0000, 0 }, new double[] { 0, 0, 1 } }; double[][] p2 = new double[][] { new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }, new double[] { 0, 0, 1 } }; double[][] p3 = new double[][] { new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }, new double[] { 0, 792, 1 } }; Matrix m1 = new Matrix(p1); Matrix m2 = new Matrix(p2); Matrix m3 = new Matrix(p3); ctms.Add(m1); ctms.Add(m2); ctms.Add(m3); //Console.WriteLine(PDF2User.setCTMTransform(rect_10, ctms)); Console.WriteLine("#########################"); Recatangle imageRect = PDF2User.setCTMTransform(rect, ctms); Console.ReadKey(); }
private static void TestCase() { Recatangle rec1 = new Recatangle(new Point(1, 1), 34, 44); Recatangle rec3 = new Recatangle(new Point(10, 10), new Point(13, 0)); // Recatangle rec4 = new Recatangle(new Point(25, -5), 5, 5); Recatangle rec4 = new Recatangle(new Point(10.08, 10.11), 30, 30); // Recatangle rec2 = new Recatangle(new Point(1, 1), 6, 6);//测试两个矩形的包含情况 // Recatangle rec2 = new Recatangle(new Point(10.08, 10.13), 11.22, 11.22);//测试两个矩形两条边重合的情况(左上角)结果正确 Recatangle rec2 = new Recatangle(new Point(10.08, 4.1), 5.19, 5.19);//测试两个矩形两条边重合的情况(左下角)结果完全正确 // Image2PatternCoordinateSystem(); // Plot2UserCoordinateSystem(); Image2pattern.Test(); Console.ReadKey(); }
/// <summary> /// content stream to User coordiate system /// </summary> /// <param name="origion"></param> /// <param name="ctms"></param> /// <param name="target"></param> private static void Image2Pattern(Recatangle origion, List <Matrix> ctms, Recatangle target) { double[][] points = contentStream2Pattern(origion, ctms); double[][] ctm = new double[][] { new double[] { 4 / 3.0000, 0, 0 }, new double[] { 0, 4 / 3.0000, 0 }, new double[] { 0, 792, 1 }, }; Matrix ctm2user = new Matrix(ctm); points = Pattern2User(points, ctm2user); //将计算出来的矩形区域的主对角线的两点分别给相应的(BLX,BLY)(BRX,BRY)赋值,并输出结果矩形 double BLX = points[0][0]; double BLY = points[0][1]; double BRX = points[1][0]; double BRY = points[1][1]; target.P.X = BLX; target.P.Y = BLY; target.Width = BRX - BLX; target.Height = BLY - BRY; }
public static Recatangle Image2UserCoordinateSystem(Recatangle target) { List <Matrix> ctms = new List <Matrix>(); Recatangle rect_10 = new Recatangle(new Point(0, 1), 1, 1); double[][] p1 = new double[][] { new double[] { 404.5714, 0, 0 }, new double[] { 0, 213.4286, 0 }, new double[] { 0, -213.4286, 1 } }; double[][] p2 = new double[][] { /** * new double[]{ 0.00185381, 0,0 }, * new double[]{ 0, 0.00351407,0 }, * **/ new double[] { 0.00185381, 0, 0 }, new double[] { 0, 0.00351407, 0 }, new double[] { 0, 0, 1 } /** * new double[]{ 1, 0,0 }, * new double[]{ 0,1,0 }, * new double[]{ 0, 0,1 } * **/ }; double[][] p21 = new double[][] { new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }, new double[] { 0, 0, 1 } }; double[][] p3 = new double[][] { new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }, new double[] { 0, -257.785, 1 } }; double[][] p4 = new double[][] { new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }, new double[] { 0, 257.785, 1 } }; Matrix m1 = new Matrix(p1); Matrix m2 = new Matrix(p2); Matrix m21 = new Matrix(p21); Matrix m3 = new Matrix(p3); Matrix m4 = new Matrix(p4); ctms.Add(m1); ctms.Add(m2); ctms.Add(m21); ctms.Add(m3); ctms.Add(m4); Console.WriteLine("###########Image2PatternCoordinateSystem##############"); //本类中调用,得到的ImageRect结果是没有映射到用户坐标空间中,只是映射到了Pattern坐标空间中 Recatangle imageRect = Image2pattern.Image2patternSystem(rect_10, ctms, target); Console.WriteLine("###########ImageRect finished!!!##############"); Recatangle BBOX = new Recatangle(new Point(-5, 5), 387.19, 257.785); List <Matrix> ctms1 = new List <Matrix>(); ctms1.Add(new Matrix(new double[][] { new double[] { 4 / 3.0000, 0, 0 }, new double[] { 0, 4 / 3.0000, 0 }, new double[] { 0, 792, 1 } })); Recatangle imageRect1 = null; //在本类中调用 imageRect1 = Image2pattern.BBOX2CoordinateSystem(imageRect, ctms1, target); Console.WriteLine("================" + imageRect1); Console.WriteLine("imageRect"); Matrix.PrintMatrix(Matrix.ConvertRect2Arr(imageRect1)); BBOX = Image2pattern.BBOX2CoordinateSystem(BBOX, ctms1, target); Console.WriteLine(BBOX); Console.WriteLine("###########BBOX finished!!!##############"); Console.WriteLine("imageRect"); Console.WriteLine("<<<<<<<<<<<<<<<<" + imageRect1); Matrix.PrintMatrix(Matrix.ConvertRect2Arr(imageRect1)); Console.WriteLine("BBOX"); Matrix.PrintMatrix(Matrix.ConvertRect2Arr(BBOX)); Console.WriteLine("相交面积"); Console.WriteLine(Rectangles.getSequare(BBOX, imageRect1)); Console.WriteLine(); return(imageRect); }
/// <summary> /// get the contentStream2Pattern co-system complete!!! /// </summary> /// <param name="origion"></param> /// <param name="ctms"></param> /// <returns></returns> private static double[][] contentStream2Pattern(Recatangle origion, List <Matrix> ctms) { double ALXO = origion.P.X; double ALYO = origion.P.Y; double ARXO = origion.P.X + origion.Width; double ARYO = origion.P.Y - origion.Height; Console.WriteLine("ALXO={0},ALYO={1},ARXO={2},ARYO={3}", ALXO, ALYO, ARXO, ARYO); double[][] points = new double[][] { new double[] { ALXO, ALYO, 1 }, //左上角的点 new double[] { ARXO, ARYO, 1 }, //右下角的点 }; //double[,]results= new double[2,3]; double[][] results = new double[][] { new double[] { 0, 0, 1 }, //左上角的点 new double[] { 0, 0, 1 }, //右下角的点 }; //first invoke Matrix ctm = ctms[0]; double[][] _ctm = ctm.Points; Console.WriteLine("origion matrix"); Matrix.PrintMatrix(points); Console.WriteLine(); Console.WriteLine("CTM matrix"); Matrix.PrintMatrix(_ctm); Console.WriteLine(); results = Matrix.MatrixMult(points, _ctm); Console.WriteLine("result matrix"); Matrix.PrintMatrix(results); Console.WriteLine(); Console.WriteLine("********************"); points = results;//update the matrix Recatangle source = new Recatangle(new Point(points[0][0], points[0][1]), points[1][0] - points[0][0], points[0][1] - points[1][1]); Recatangle target = new Recatangle(new Point(0, 0), 404.5725, 213.4275); bool canClipse = Rectangles.canClip(source, target); //有交集 // points[1][1] = -213.4275; canClipse = true; if (canClipse) { for (int i = 1; i < ctms.Count; i++) { ctm = ctms[i]; _ctm = ctm.Points; Console.WriteLine("origion matrix"); Matrix.PrintMatrix(points); Console.WriteLine(); Console.WriteLine("CTM matrix"); Matrix.PrintMatrix(_ctm); Console.WriteLine(); results = Matrix.MatrixMult(points, _ctm); Console.WriteLine("result matrix"); Matrix.PrintMatrix(results); Console.WriteLine(); Console.WriteLine("********************"); points = results;//update the matrix } } return(points); }
private static void TestCase() { Recatangle rec1 = new Recatangle(new Point(1, 1), 34, 44); Recatangle rec3 = new Recatangle(new Point(10, 10), new Point(13, 0)); // Recatangle rec4 = new Recatangle(new Point(25, -5), 5, 5); Recatangle rec4 = new Recatangle(new Point(10.08, 10.11), 30, 30); // Recatangle rec2 = new Recatangle(new Point(1, 1), 6, 6);//测试两个矩形的包含情况 // Recatangle rec2 = new Recatangle(new Point(10.08, 10.13), 11.22, 11.22);//测试两个矩形两条边重合的情况(左上角)结果正确 Recatangle rec2 = new Recatangle(new Point(10.08, 4.1), 5.19, 5.19);//测试两个矩形两条边重合的情况(左下角)结果完全正确 /** * * Console.WriteLine(rec1); * Console.WriteLine(rec3); * Console.WriteLine(Rectangles.isOverlap(rec1,rec3)); * // Console.WriteLine(decimal.Round(decimal.Parse("0.3333333"), 2)); * Console.WriteLine(Rectangles.getSequare(rec1,rec3)); * * * * Console.WriteLine(Rectangles.getSequare(rec2, rec4)); * Console.WriteLine("================================"); * Console.WriteLine("矩阵部分"); * //示例矩阵 * double[][] matrix1 = new double[][] * { * new double[] { 1, 2, 3 }, * new double[] { 4, 5, 6 }, * new double[] { 7, 8, 9 } * }; * double[][] matrix2 = new double[][] * { * new double[] { 2, 3, 4 }, * new double[] { 5, 6, 7 }, * new double[] { 8, 9, 10 } * }; * * //矩阵加法 * Matrix.PrintMatrix(Matrix.MatrixAdd(matrix1, matrix2)); * Console.WriteLine(); * //矩阵取负 * Matrix.PrintMatrix(Matrix.NegtMatrix(matrix1)); * Console.WriteLine(); * //矩阵数乘 * Matrix.PrintMatrix(Matrix.MatrixMult(matrix1, 3)); * Console.WriteLine(); * //矩阵乘法 * Matrix.PrintMatrix(Matrix.MatrixMult( * new double[][] { * new double[]{ 4, -1, 2 }, * new double[]{ 1, 1, 0 }, * new double[]{ 0, 3, 1 }}, * new double[][] { * new double[]{ 1, 2 }, * new double[]{ 0, 1 }, * new double[]{ 3, 0 }})); * * Matrix.PrintMatrix(Matrix.MatrixMult(//成功 * new double[][] { * new double[]{ 0.10, 0.30, 0.15 }, * new double[]{ 0.30, 0.40, 0.25 }, * new double[]{ 0.10, 0.20, 0.15 }}, * new double[][] { * new double[]{ 4000, 4500,4500,4000 }, * new double[]{ 2000,2800,2400,2200}, * new double[]{ 5800,6200,6000,6000}})); * * Console.WriteLine(); * * Matrix.PrintMatrix(Matrix.MatrixMult(//成功 * new double[][] { * new double[]{ 0.10, 0.30, 0.15 }, * new double[]{ 0.30, 0.40, 0.25 }, * new double[]{ 0.10, 0.20, 0.15 }}, * new double[][] { * new double[]{ 4000, 4500,4500,4000 }, * new double[]{ 2000,2800,2400,2200}, * new double[]{ 5800,6200,6000,6000}})); * * * **/ Image2PatternCoordinateSystem(); Plot2UserCoordinateSystem(); }
/// <summary> /// return the two Recatangle's Sequare /// </summary> /// <param name="rectA"></param> /// <param name="rectB"></param> /// <returns></returns> public static double getSequare(Recatangle rectA, Recatangle rectB) { double result = 0.0; if (isOverlap(rectA, rectB) && isSame(rectA, rectB))//首先判断两个矩形是否完全重合 { result = rectA.Width * rectA.Height; Console.WriteLine("两个图形完全重合了!!!两个矩形相交的面积是{0}", result); return(result); } //第1个矩形左上角的坐标 double ALX = rectA.P.X; double ALY = rectA.P.Y; //第1个矩形右下角的坐标 double ARX = ALX + rectA.Width; double ARY = ALY - rectA.Height; //第2个矩形左上角的坐标 double BLX = rectB.P.X; double BLY = rectB.P.Y; //第2个矩形右下角的坐标 double BRX = BLX + rectB.Width; double BRY = BLY - rectB.Height; /** * double min1 = Math.Max(Math.Min(ALX,ARX),Math.Min(BLX,BRX)); * double min2 = Math.Max(Math.Min(ALY, ARY), Math.Min(BLY, BRY)); * double max1 = Math.Min(Math.Max(ALX, ARX), Math.Max(BLX, BRX)); * * double max2 = Math.Min(Math.Max(ALY, ARY), Math.Max(BLY, BRY)); */ double min1 = getMax(getMin(ALX, ARX), getMin(BLX, BRX)); double min2 = getMax(getMin(ALY, ARY), getMin(BLY, BRY)); double max1 = getMin(getMax(ALX, ARX), getMax(BLX, BRX)); double max2 = getMin(getMax(ALY, ARY), getMax(BLY, BRY)); //如果进入运算的是小数,则使用这种算法会漏掉包含的情况,所以加个bool类型的变量,判断是否直接含有两个矩形嵌套完全包含的情况,以免计算有错误 bool isDoubleContains = true; //想错了,原来的算法是完全正确无误的 // if (ALX >= BLX && ALY >= BLY && ARX >= BRX && BRY >= ARY) isDoubleContains = false;//说明A包含B // if (ALX <= BLX && ALY <= BLY && ARX <= BRX && BRY <= ARY) isDoubleContains = false;//说明B包含A if (min1 < max1 && max2 > min2 && isDoubleContains) { Console.WriteLine("ALX={0},ALY={1},ARX={2},ARY={3}", ALX, ALY, ARX, ARY); Console.WriteLine("BLX={0},BLY={1},BRX={2},BRY={3}", BLX, BLY, BRX, BRY); Console.WriteLine("min1={0},min2={1},max1={2},max2={3}", min1, min2, max1, max2); Console.WriteLine("max1 - min1={0},max2 - min2={1},(max1 - min1) * (max2 - min2)={2}", max1 - min1, max2 - min2, (max1 - min1) * (max2 - min2)); result = Convert.ToDouble(decimal.Round(decimal.Parse("" + (max1 - min1) * (max2 - min2)), 2)); } else { //在这个判断条件当中处理了有关两个矩形的包含的情况 //说明这两个矩形有相互包含的情况 if (rectA.Width * rectA.Height > rectB.Width * rectB.Height && (max1 - min1) * (max2 - min2) > 0) //说明recA包含recB { result = rectB.Height * rectB.Width; } else if (rectA.Width * rectA.Height < rectB.Width * rectB.Height && (max1 - min1) * (max2 - min2) > 0)//说明rectB包含rectA { result = rectA.Height * rectA.Width; } else { Console.WriteLine("两个矩形相离!!!"); Console.WriteLine("Sorry,Somthings Wrong!!,Sequares=0.00"); result = 0.00; } } return(result); }
/// <summary> /// this method contains the value of User坐标映射 /// </summary> /// <param name="origion"></param> /// <param name="ctms"></param> /// <param name="target"></param> /// <returns></returns> private static Recatangle Plot2UserCoordinateSystem(Recatangle origion, List <Matrix> ctms, Recatangle target) { double ALXO = origion.P.X; double ALYO = origion.P.Y; double ARXO = origion.P.X + origion.Width; double ARYO = origion.P.Y - origion.Height; Console.WriteLine("ALXO={0},ALYO={1},ARXO={2},ARYO={3}", ALXO, ALYO, ARXO, ARYO); double[][] points = new double[][] { new double[] { ALXO, ALYO, 1 }, //左上角的点 new double[] { ARXO, ARYO, 1 }, //右下角的点 }; double[][] results = new double[][] { new double[] { 0, 0, 1 }, //左上角的点 new double[] { 0, 0, 1 }, //右下角的点 }; Matrix ctm = null; double[][] _ctm = null; for (int i = 0; i <= 1; i++) { //first invoke ctm = ctms[i]; _ctm = ctm.Points; Console.WriteLine("origion matrix"); Matrix.PrintMatrix(points); Console.WriteLine(); Console.WriteLine("CTM matrix"); Matrix.PrintMatrix(_ctm); Console.WriteLine(); results = Matrix.MatrixMult(points, _ctm); Console.WriteLine("result matrix"); Matrix.PrintMatrix(results); Console.WriteLine(); Console.WriteLine("********************"); points = results;//update the matrix } #region clip operation /* * 中间截取一段执行Clip操作 */ Recatangle source = new Recatangle(new Point(points[0][0], points[0][1]), points[1][0] - points[0][0], points[0][1] - points[1][1]); target = new Recatangle(new Point(0, 0), 612, 792); bool canClipse = Rectangles.canClip(source, target); //有交集 // points[1][1] = -213.4275; canClipse = true; //Clip操作执行完成 #endregion ctm = ctms[2]; _ctm = ctm.Points; Console.WriteLine("origion matrix"); Matrix.PrintMatrix(points); Console.WriteLine(); Console.WriteLine("CTM matrix"); Matrix.PrintMatrix(_ctm); Console.WriteLine(); results = Matrix.MatrixMult(points, _ctm); Console.WriteLine("result matrix"); Matrix.PrintMatrix(results); Console.WriteLine(); Console.WriteLine("********************"); points = results;//update the matrix //将计算出来的矩形区域的主对角线的两点分别给相应的(BLX,BLY)(BRX,BRY)赋值,并输出结果矩形 double BLX = points[0][0]; double BLY = points[0][1]; double BRX = points[1][0]; double BRY = points[1][1]; target.P.X = BLX; target.P.Y = BLY; target.Width = BRX - BLX; target.Height = BLY - BRY; return(target); }
private static void Image2PatternCoordinateSystem() { Console.WriteLine("=========================="); Recatangle rect_10 = new Recatangle(new Point(0, 1), 1, 1); List <Matrix> ctms = new List <Matrix>(); double[][] p1 = new double[][] { new double[] { 404.5714, 0, 0 }, new double[] { 0, 213.4286, 0 }, new double[] { 0, -213.4286, 1 } }; double[][] p2 = new double[][] { new double[] { 0.00185381, 0, 0 }, new double[] { 0, 0.00351407, 0 }, new double[] { 0, 0, 1 } }; double[][] p3 = new double[][] { new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }, new double[] { 0, -257.785, 1 } }; double[][] p4 = new double[][] { new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }, new double[] { 0, 257.785, 1 } }; Matrix m1 = new Matrix(p1); Matrix m2 = new Matrix(p2); Matrix m3 = new Matrix(p3); Matrix m4 = new Matrix(p4); ctms.Add(m1); ctms.Add(m2); ctms.Add(m3); ctms.Add(m4); //Console.WriteLine(PDF2User.setCTMTransform(rect_10, ctms)); Console.WriteLine("###########Image2PatternCoordinateSystem##############"); Recatangle imageRect = PDF2User.setCTMTransform(rect_10, ctms); Console.WriteLine("###########ImageRect finished!!!##############"); Recatangle BBOX = new Recatangle(new Point(-5, 5), 387.19, 257.785); List <Matrix> ctms1 = new List <Matrix>(); ctms1.Add(new Matrix(new double[][] { new double[] { 4 / 3.0000, 0, 0 }, new double[] { 0, 4 / 3.0000, 0 }, new double[] { 0, 792, 1 } })); BBOX = PDF2User.setCTMTransform(BBOX, ctms); Console.WriteLine("###########BBOX finished!!!##############"); Console.WriteLine("imageRect"); Matrix.PrintMatrix(Matrix.ConvertRect2Arr(imageRect)); Console.WriteLine("BBOX"); Matrix.PrintMatrix(Matrix.ConvertRect2Arr(BBOX)); Console.WriteLine("相交面积"); Console.WriteLine(Rectangles.getSequare(imageRect, BBOX)); Console.WriteLine(); //Console.ReadKey(); }