Rectangles Intersection

Rectangle bounds collision

A simple method for testing if two rectangles, r1 and r2 (in the form of objects {x:[x position], y:[y position], w:[width], h:[height]}) are colliding / overlapping in 2D space.

View example

function rectanglesIntersect(r1, r2)
{
	return (r1.x <= (r2.x + r2.w) && (r1.x + r1.w) >= r2.x &&
		r1.y <= (r2.y + r2.h) && (r1.y + r1.h) >= r2.y);
}

Page loaded in 0.01 second(s).