Intersection of Rectangles?

Miscellaneous Forums/General Discussion/Intersection of Rectangles?

Hi,

I have two rects, sx1,sy1,sx2,sy2 and dx1,dy1,dx2,dy2.

I would like to collide one rect with the other rect, but return a third rect: x1,y1,x2,y2 with the area the two of them overlap as.

How is this done? I've just hurt my brain over what seems to be a really simple problem!

http://www.blitzbasic.com/Community/posts.php?topic=52883#590725

Thanks Tim, isn't that overkill though?

What are you attempting?

a) To create a 3rd Dirty Rect? or
b) To identify areas of potential overdraw? or
c) bit of both to identify the fastest method of render.

Simple Rect

Diablo, Nice code, one for the collection, thanks !

Hiya,

Just wanted to get the coords of where and how much they overlap.

Will look at diablos code too :)

Do it on paper. Trust me, you'll be suprized how simple the problem can be after you jot everything down.