From: G DOT DegliEsposti AT ads DOT it To: djgpp AT delorie DOT com Message-ID: Date: Thu, 2 Oct 1997 10:45:26 +0200 Subject: Re: Re: collision detection Mime-Version: 1.0 Content-type: text/plain; charset=us-ascii Precedence: bulk Hello everybody. Andrew Deren wrote: > > Does anyone know how to detect if two rectangles overlap each other at > some point. Let's say we have something like this: > > typedef struct RECT { > int x1, y1, x2, y2; > } RECT; > In many years I have seen it is not possible to solve this problem without lots of tests, unless you have some special conditions (and usually you have not :-) You have to test for all vertices of A beeing inside B *and* all vertices of B beeing inside A, otherwise you can have particular cases where it does not work. I alway use another way, which costs almost the same but is simplier to write: if A and B overlap each other then they have an intersection, so I test if they intersect and the intersection is a real rectangle: This tests if the intersection of A and B is a valid rectangle (ie x1