rectint

Area of intersection between axis-aligned rectangles.

Category: Mathematics > Computational Geometry

Syntax

A = rectint(R1, R2)

Overlap area of every rectangle in R1 with every rectangle in R2.

Description

The overlap of two rectangles is itself a rectangle whose width is the overlap of the x intervals and whose height is the overlap of the y intervals; if either is zero or negative the area is 0. Rectangles that merely touch along an edge have no overlap.

Input arguments

R1, R2
Matrices with one rectangle per row in the form [x y width height], where (x, y) is the lower-left corner.

Output arguments

A
Matrix with size(R1, 1) rows and size(R2, 1) columns. Entry (i, j) is the overlap area of rectangle i of R1 and rectangle j of R2.

Example

Overlap of a pair of rectangles

A = [0 0 2 2];
B = [1 1 2 2; 5 5 1 1];
rectint(A, B)
Output
ans = 1×2

     1     0

See also

overlaps polyshape boundingbox polyarea