using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IntelligentControlForsx.Service { public class IsRectangleCross { //判断矩形是否相交 public static bool JudgeRectangleIntersect(int RecAleftX, int RecAleftY, int RecArightX, int RecArightY, int RecBleftX, int RecBleftY, int RecBrightX, int RecBrightY) { bool isIntersect = false; try { int zx = getAbsluteValue(RecAleftX + RecArightX - RecBleftX - RecBrightX); int x = getAbsluteValue(RecAleftX - RecArightX) + getAbsluteValue(RecBleftX - RecBrightX); int zy = getAbsluteValue(RecAleftY + RecArightY - RecBleftY - RecBrightY); int y = getAbsluteValue(RecAleftY - RecArightY) + getAbsluteValue(RecBleftY - RecBrightY); if (zx <= x && zy <= y) //需要确认两矩形边线重合是否定义为相交 此处定义为相交。 { isIntersect = true; } } catch (Exception ex) { string str = ex.Message; } return isIntersect; } private static int getAbsluteValue(int douValue) { if (douValue >= 0) { return douValue; } else { return douValue * -1; } } } }