TITLE: How to find rectangle intersection on a coordinate plane
QUESTION [7 upvotes]: Given the coordinates of two rectangles on a coordinate plane, what would be the easiest way to find the coordinates of the intersecting rectangle of the two?
I am trying to do this programatically.

REPLY [5 votes]: Working from Zwarmapapa's solution, you probably want to check that the rectangles actually overlap, and optionally that the overlap has a non-zero area. 
When there is no overlap, the two coordinates will be reversed (top left will actually be bottom right and vice-versa).
If you want the rectangles with zero area (edge/corner intersection), change the two less than checks to less than or equal.
Rectangle r1 = rect1;
Rectangle r2 = rect2;
Rectangle intersectionRect = null;

int leftX   = Math.max( r1.getX(), r2.getX() );
int rightX  = Math.min( r1.getX() + r1.getWidth(), r2.getX() + r2.getWidth() );
int topY    = Math.max( r1.getY(), r2.getY() );
int bottomY = Math.min( r1.getY() + r1.getHeight(), r2.getY() + r2.getHeight() );

if ( leftX < rightX && topY < bottomY ) {
  intersectionRect = new Rectangle( leftX, topY, rightX-leftX, bottomY-topY );
} else {
  // Rectangles do not overlap, or overlap has an area of zero (edge/corner overlap)
}