<ca********@hotmail.com> wrote in message

news:11**********************@z14g2000cwz.googlegr oups.com...

Can some body share the code to find the intersection of two

rectangles?

Unless the rectangles are axis-aligned, you're pretty much in

the general case of Convex Polygon Intersection (--> Google).

If your rectangles are given in 2D as Top,Left,Bottom,Right

coordinates, as typical for GUI programming, then it's simply:

intersect.Left = max(a.Left, b.Left);

intersect.Top = max(a.Top, b.Top);

intersect.Right = min(a.Right, b.Right );

intersect.Bottom = min(a.Bottom, b.Bottom);

And the intersection is empty unless

intersect.Right > intersect.Left

&& intersect.Bottom > intersect.Top

hth-Ivan

--

http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form