public Rectangle Intersect(Rectangle other) { //create default triangle to return if no instersect found Rectangle intersect = new Rectangle(); //find origin of intersect rectangle MyPoint newOrigin = new MyPoint(Math.Max(origin.x, other.origin.x), Math.Max(origin.y, other.origin.y)); if (this.ContainsPoint(newOrigin) && other.ContainsPoint(newOrigin)) { //if origin of intersect is found in both rectangles, find the width and length int newWidth = Math.Min(origin.x + width, other.origin.x + other.width); int newLength = Math.Min(origin.y + length, other.origin.y + other.length); if (newWidth != 0 && newLength != 0) { //if both width and height are not zero, set properties of intersect rectangle intersect.Translate(newOrigin); intersect.width = newWidth; intersect.length = newLength; } } return(intersect); }