示例#1
0
        /// <summary>
        /// 判断两个正方形是否有重叠的区域(包括共用一条边)
        /// </summary>
        /// <param name="rect1">正方形1</param>
        /// <param name="rect2">正方形2</param>
        /// <returns>如果重叠则返回true,否则返回false</returns>
        public static bool CheckTwoRectanglesIntersect(Rectangle rect1, Rectangle rect2)
        {
            bool result = ((((rect1.X <= (rect2.X + rect2.Width)) && (rect2.X <= (rect1.X + rect1.Width))) && (rect1.Y <= (rect2.Y + rect2.Height))) && (rect2.Y <= (rect1.Y + rect1.Height)));

            return result;
        }
示例#2
0
        public static bool PointInRectangle(Point p, Rectangle rect)
        {
            bool result = ((p.X >= rect.X) && (p.X <= (rect.X + rect.Width))) && ((p.Y >= rect.Y) && (p.Y <= (rect.Y + rect.Height)));

            return result;
        }
示例#3
0
        public static bool PointInTheMaxRectangle(Point p, Polygon polygon)
        {
            double maxX = polygon.Points.Max(u => u.X);
            double minX = polygon.Points.Min(u => u.X);
            double maxY = polygon.Points.Max(u => u.Y);
            double minY = polygon.Points.Min(u => u.Y);

            LineSegment line = new LineSegment(new Point(maxX, maxY), new Point(minX, minY));

            Rectangle rec = new Rectangle(line);

            return Rectangle.PointInRectangle(p, rec);
        }